diff --git a/lib/noosfero/api/entities.rb b/lib/noosfero/api/entities.rb index 527c1a1..5166410 100644 --- a/lib/noosfero/api/entities.rb +++ b/lib/noosfero/api/entities.rb @@ -69,6 +69,13 @@ module Noosfero class Person < Profile root 'people', 'person' expose :user, :using => UserBasic, documentation: {type: 'User', desc: 'The user data of a person' } +# expose :vote_count, if: lambda { |object, options| options[:fields].include?('vote_count') == :full } + expose :vote_count + expose :comments_count do |person, options| + person.comments.count + end + + end class Enterprise < Profile diff --git a/test/unit/api/people_test.rb b/test/unit/api/people_test.rb index 119c38c..1540921 100644 --- a/test/unit/api/people_test.rb +++ b/test/unit/api/people_test.rb @@ -180,4 +180,16 @@ class PeopleTest < ActiveSupport::TestCase assert_equal another_name, person.name end + PERSON_ATTRIBUTES = %w(vote_count comments_count) + + PERSON_ATTRIBUTES.map do |attribute| + + define_method "test_should_expose_#{attribute}_attribute_in_person_enpoints" do + get "/api/v1/people/me?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_not_nil json['person'][attribute] + end + + end + end -- libgit2 0.21.2