Commit 8c6c49ca0af55f466247863e577ac50590805c40
1 parent
ce08b7cc
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
return vote_count and comments_count attributes from person profile
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
lib/noosfero/api/entities.rb
| ... | ... | @@ -69,6 +69,13 @@ module Noosfero |
| 69 | 69 | class Person < Profile |
| 70 | 70 | root 'people', 'person' |
| 71 | 71 | expose :user, :using => UserBasic, documentation: {type: 'User', desc: 'The user data of a person' } |
| 72 | +# expose :vote_count, if: lambda { |object, options| options[:fields].include?('vote_count') == :full } | |
| 73 | + expose :vote_count | |
| 74 | + expose :comments_count do |person, options| | |
| 75 | + person.comments.count | |
| 76 | + end | |
| 77 | + | |
| 78 | + | |
| 72 | 79 | end |
| 73 | 80 | |
| 74 | 81 | class Enterprise < Profile | ... | ... |
test/unit/api/people_test.rb
| ... | ... | @@ -180,4 +180,16 @@ class PeopleTest < ActiveSupport::TestCase |
| 180 | 180 | assert_equal another_name, person.name |
| 181 | 181 | end |
| 182 | 182 | |
| 183 | + PERSON_ATTRIBUTES = %w(vote_count comments_count) | |
| 184 | + | |
| 185 | + PERSON_ATTRIBUTES.map do |attribute| | |
| 186 | + | |
| 187 | + define_method "test_should_expose_#{attribute}_attribute_in_person_enpoints" do | |
| 188 | + get "/api/v1/people/me?#{params.to_query}" | |
| 189 | + json = JSON.parse(last_response.body) | |
| 190 | + assert_not_nil json['person'][attribute] | |
| 191 | + end | |
| 192 | + | |
| 193 | + end | |
| 194 | + | |
| 183 | 195 | end | ... | ... |