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 | 15 | end |
16 | 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 | 24 | end |
19 | 25 | end |
20 | 26 | ... | ... |
lib/proposals_discussion_plugin/api.rb
... | ... | @@ -6,8 +6,9 @@ class ProposalsDiscussionPlugin::API < Grape::API |
6 | 6 | get ':id/ranking' do |
7 | 7 | article = find_article(environment.articles, params[:id]) |
8 | 8 | current_page = paginate(article.ranking) |
9 | + present(current_page, :with => Noosfero::API::Entities::RankingItem) | |
9 | 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 | 12 | end |
12 | 13 | |
13 | 14 | post ':id/propose' do | ... | ... |
lib/proposals_discussion_plugin/ranking_item.rb
test/unit/api_test.rb
... | ... | @@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase |
51 | 51 | |
52 | 52 | should 'sanitize proposal' do |
53 | 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 | 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 | 59 | :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"} |
60 | 60 | assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do |
61 | 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 | 16 | assert proposal.ranking_item |
17 | 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 | 25 | end | ... | ... |