Commit 8c6c49ca0af55f466247863e577ac50590805c40

Authored by Leandro Santos
1 parent ce08b7cc

return vote_count and comments_count attributes from person profile

lib/noosfero/api/entities.rb
@@ -69,6 +69,13 @@ module Noosfero @@ -69,6 +69,13 @@ module Noosfero
69 class Person < Profile 69 class Person < Profile
70 root 'people', 'person' 70 root 'people', 'person'
71 expose :user, :using => UserBasic, documentation: {type: 'User', desc: 'The user data of a person' } 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 end 79 end
73 80
74 class Enterprise < Profile 81 class Enterprise < Profile
test/unit/api/people_test.rb
@@ -180,4 +180,16 @@ class PeopleTest &lt; ActiveSupport::TestCase @@ -180,4 +180,16 @@ class PeopleTest &lt; ActiveSupport::TestCase
180 assert_equal another_name, person.name 180 assert_equal another_name, person.name
181 end 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 end 195 end