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 | 39 | end |
40 | 40 | |
41 | 41 | def self.expose_optional_field?(field, options = {}) |
42 | - return false if options[:params].nil? | |
42 | + return false if options[:params].nil? | |
43 | 43 | optional_fields = options[:params][:optional_fields] || [] |
44 | 44 | optional_fields.include?(field.to_s) |
45 | 45 | end |
... | ... | @@ -160,6 +160,9 @@ module Api |
160 | 160 | expose :articles_count do |person, options| |
161 | 161 | person.articles.count |
162 | 162 | end |
163 | + expose :friends_count do |person, options| | |
164 | + person.friends.size | |
165 | + end | |
163 | 166 | end |
164 | 167 | |
165 | 168 | class Enterprise < Profile |
... | ... | @@ -316,7 +319,7 @@ module Api |
316 | 319 | end |
317 | 320 | expose :params, :if => lambda { |activity, options| activity.kind_of?(ActionTracker::Record)} |
318 | 321 | expose :content, :if => lambda { |activity, options| activity.kind_of?(Scrap)} |
319 | - expose :verb do |activity, options| | |
322 | + expose :verb do |activity, options| | |
320 | 323 | activity.kind_of?(Scrap) ? 'leave_scrap' : activity.verb |
321 | 324 | end |
322 | 325 | ... | ... |
test/api/people_test.rb
... | ... | @@ -369,7 +369,7 @@ class PeopleTest < ActiveSupport::TestCase |
369 | 369 | assert_equal "www.blog.org", json['person']['additional_data']['Custom Blog'] |
370 | 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 | 374 | PERSON_ATTRIBUTES.map do |attribute| |
375 | 375 | define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_does_not_contain_the_attribute" do | ... | ... |