Commit 45799bf12bdaba541890fa345f76c161d041276f
1 parent
32da9780
Exists in
master
and in
3 other branches
Add proposal body to ranking in api
Showing
5 changed files
with
20 additions
and
5 deletions
Show diff stats
lib/ext/entities.rb
@@ -15,6 +15,12 @@ module Noosfero | @@ -15,6 +15,12 @@ module Noosfero | ||
15 | end | 15 | end |
16 | end | 16 | end |
17 | 17 | ||
18 | + class RankingItem < Entity | ||
19 | + root :proposals, :proposal | ||
20 | + expose :id, :position, :abstract, :body, :votes_for, :votes_against | ||
21 | + expose :hits, :effective_support, :proposal_id, :created_at, :updated_at | ||
22 | + end | ||
23 | + | ||
18 | end | 24 | end |
19 | end | 25 | end |
20 | 26 |
lib/proposals_discussion_plugin/api.rb
@@ -6,8 +6,9 @@ class ProposalsDiscussionPlugin::API < Grape::API | @@ -6,8 +6,9 @@ class ProposalsDiscussionPlugin::API < Grape::API | ||
6 | get ':id/ranking' do | 6 | get ':id/ranking' do |
7 | article = find_article(environment.articles, params[:id]) | 7 | article = find_article(environment.articles, params[:id]) |
8 | current_page = paginate(article.ranking) | 8 | current_page = paginate(article.ranking) |
9 | + present(current_page, :with => Noosfero::API::Entities::RankingItem) | ||
9 | #FIXME find a better way to get updated_at date | 10 | #FIXME find a better way to get updated_at date |
10 | - {:proposals => current_page, :updated_at => current_page.blank? ? DateTime.now : current_page.first.updated_at} | 11 | + present :updated_at, current_page.blank? ? DateTime.now : current_page.first.updated_at |
11 | end | 12 | end |
12 | 13 | ||
13 | post ':id/propose' do | 14 | post ':id/propose' do |
lib/proposals_discussion_plugin/ranking_item.rb
@@ -4,4 +4,6 @@ class ProposalsDiscussionPlugin::RankingItem < ActiveRecord::Base | @@ -4,4 +4,6 @@ class ProposalsDiscussionPlugin::RankingItem < ActiveRecord::Base | ||
4 | 4 | ||
5 | attr_accessible :proposal, :abstract, :votes_for, :votes_against, :hits, :effective_support | 5 | attr_accessible :proposal, :abstract, :votes_for, :votes_against, :hits, :effective_support |
6 | 6 | ||
7 | + delegate :body, :to => :proposal | ||
8 | + | ||
7 | end | 9 | end |
test/unit/api_test.rb
@@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase | @@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase | ||
51 | 51 | ||
52 | should 'sanitize proposal' do | 52 | should 'sanitize proposal' do |
53 | discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id) | 53 | discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id) |
54 | - topic = fast_create(ProposalsDiscussionPlugin::Topic, | ||
55 | - :profile_id => user.person.id, | 54 | + topic = fast_create(ProposalsDiscussionPlugin::Topic, |
55 | + :profile_id => user.person.id, | ||
56 | :parent_id => discussion.id) | 56 | :parent_id => discussion.id) |
57 | - params[:article] = {:name => "Proposal name", :abstract => "Proposal <iframe>Test</iframe> abstract", | ||
58 | - :type => 'ProposalsDiscussionPlugin::Proposal', | 57 | + params[:article] = {:name => "Proposal name", :abstract => "Proposal <iframe>Test</iframe> abstract", |
58 | + :type => 'ProposalsDiscussionPlugin::Proposal', | ||
59 | :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"} | 59 | :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"} |
60 | assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do | 60 | assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do |
61 | post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}" | 61 | post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}" |
test/unit/ranking_item_test.rb
@@ -16,4 +16,10 @@ class RankingItemTest < ActiveSupport::TestCase | @@ -16,4 +16,10 @@ class RankingItemTest < ActiveSupport::TestCase | ||
16 | assert proposal.ranking_item | 16 | assert proposal.ranking_item |
17 | end | 17 | end |
18 | 18 | ||
19 | + should 'return body of a proposal' do | ||
20 | + proposal = ProposalsDiscussionPlugin::Proposal.create!(:name => 'test', :abstract => 'abstract', :body => 'body', :profile => profile, :parent => discussion) | ||
21 | + discussion.update_ranking | ||
22 | + assert_equal 'body', proposal.ranking_item.body | ||
23 | + end | ||
24 | + | ||
19 | end | 25 | end |