Commit 09952f2a15015e0ce79dd8c53c8fa1949fef44e9
1 parent
fc09b34b
Exists in
master
and in
7 other branches
Return ranking position of a proposan in api
Showing
3 changed files
with
26 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,13 @@ |
1 | +module Noosfero | |
2 | + module API | |
3 | + module Entities | |
4 | + | |
5 | + class ArticleBase < Entity | |
6 | + expose :ranking_position do |article, options| | |
7 | + article.kind_of?(ProposalsDiscussionPlugin::Proposal) && article.ranking_item.present? ? article.ranking_item.position : nil | |
8 | + end | |
9 | + end | |
10 | + | |
11 | + end | |
12 | + end | |
13 | +end | ... | ... |
lib/proposals_discussion_plugin/proposals_holder.rb
... | ... | @@ -55,6 +55,7 @@ class ProposalsDiscussionPlugin::ProposalsHolder < Folder |
55 | 55 | ProposalsDiscussionPlugin::RankingItem.new(:proposal => proposal, :abstract => proposal.abstract, :votes_for => proposal.votes_for, :votes_against => proposal.votes_against, :hits => proposal.hits, :effective_support => effective_support) |
56 | 56 | end |
57 | 57 | ranking.sort_by { |p| p.effective_support }.reverse |
58 | + ranking.each_with_index { |p, i| p.position = i+1 } | |
58 | 59 | end |
59 | 60 | |
60 | 61 | def update_ranking | ... | ... |
test/unit/api_test.rb
... | ... | @@ -65,4 +65,16 @@ class APITest < ActiveSupport::TestCase |
65 | 65 | assert_equal "This is a malicious body SearchParam", task.article.body |
66 | 66 | end |
67 | 67 | |
68 | + should 'return article position when list proposals' do | |
69 | + discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id) | |
70 | + topic = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => user.person.id, :parent_id => discussion.id) | |
71 | + proposal = fast_create(ProposalsDiscussionPlugin::Proposal, :profile_id => user.person.id, :parent_id => topic.id) | |
72 | + params[:content_type] = 'ProposalsDiscussionPlugin::Proposal' | |
73 | + topic.update_ranking | |
74 | + | |
75 | + get "/api/v1/articles/?#{params.to_query}" | |
76 | + json = JSON.parse(last_response.body) | |
77 | + assert_includes json["articles"].map { |a| a["ranking_position"] }, 1 | |
78 | + end | |
79 | + | |
68 | 80 | end | ... | ... |