Commit fd1dd4353837a405955db912437d044f0aac1261
1 parent
644db6c1
Exists in
staging
Exposing friends count
Showing
2 changed files
with
6 additions
and
3 deletions
Show diff stats
app/api/entities.rb
@@ -39,7 +39,7 @@ module Api | @@ -39,7 +39,7 @@ module Api | ||
39 | end | 39 | end |
40 | 40 | ||
41 | def self.expose_optional_field?(field, options = {}) | 41 | def self.expose_optional_field?(field, options = {}) |
42 | - return false if options[:params].nil? | 42 | + return false if options[:params].nil? |
43 | optional_fields = options[:params][:optional_fields] || [] | 43 | optional_fields = options[:params][:optional_fields] || [] |
44 | optional_fields.include?(field.to_s) | 44 | optional_fields.include?(field.to_s) |
45 | end | 45 | end |
@@ -160,6 +160,9 @@ module Api | @@ -160,6 +160,9 @@ module Api | ||
160 | expose :articles_count do |person, options| | 160 | expose :articles_count do |person, options| |
161 | person.articles.count | 161 | person.articles.count |
162 | end | 162 | end |
163 | + expose :friends_count do |person, options| | ||
164 | + person.friends.size | ||
165 | + end | ||
163 | end | 166 | end |
164 | 167 | ||
165 | class Enterprise < Profile | 168 | class Enterprise < Profile |
@@ -316,7 +319,7 @@ module Api | @@ -316,7 +319,7 @@ module Api | ||
316 | end | 319 | end |
317 | expose :params, :if => lambda { |activity, options| activity.kind_of?(ActionTracker::Record)} | 320 | expose :params, :if => lambda { |activity, options| activity.kind_of?(ActionTracker::Record)} |
318 | expose :content, :if => lambda { |activity, options| activity.kind_of?(Scrap)} | 321 | expose :content, :if => lambda { |activity, options| activity.kind_of?(Scrap)} |
319 | - expose :verb do |activity, options| | 322 | + expose :verb do |activity, options| |
320 | activity.kind_of?(Scrap) ? 'leave_scrap' : activity.verb | 323 | activity.kind_of?(Scrap) ? 'leave_scrap' : activity.verb |
321 | end | 324 | end |
322 | 325 |
test/api/people_test.rb
@@ -369,7 +369,7 @@ class PeopleTest < ActiveSupport::TestCase | @@ -369,7 +369,7 @@ class PeopleTest < ActiveSupport::TestCase | ||
369 | assert_equal "www.blog.org", json['person']['additional_data']['Custom Blog'] | 369 | assert_equal "www.blog.org", json['person']['additional_data']['Custom Blog'] |
370 | end | 370 | end |
371 | 371 | ||
372 | - PERSON_ATTRIBUTES = %w(vote_count comments_count articles_count following_articles_count) | 372 | + PERSON_ATTRIBUTES = %w(vote_count comments_count articles_count following_articles_count friends_count) |
373 | 373 | ||
374 | PERSON_ATTRIBUTES.map do |attribute| | 374 | PERSON_ATTRIBUTES.map do |attribute| |
375 | define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_does_not_contain_the_attribute" do | 375 | define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_does_not_contain_the_attribute" do |