[Git][noosfero/noosfero][master] 2 commits: Exposing friends count
Leandro Nunes
gitlab at mg.gitlab.com
Mon Sep 5 11:26:50 BRT 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
fd1dd435 by Evandro Junior at 2016-09-02T17:54:29-03:00
Exposing friends count
- - - - -
2baaf088 by Leandro Nunes at 2016-09-05T14:25:23+00:00
Merge branch 'expose_friends_count_in_api' into 'master'
Exposing friends count in the API
See merge request !1016
- - - - -
2 changed files:
- app/api/entities.rb
- test/api/people_test.rb
Changes:
=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -39,7 +39,7 @@ module Api
end
def self.expose_optional_field?(field, options = {})
- return false if options[:params].nil?
+ return false if options[:params].nil?
optional_fields = options[:params][:optional_fields] || []
optional_fields.include?(field.to_s)
end
@@ -160,6 +160,9 @@ module Api
expose :articles_count do |person, options|
person.articles.count
end
+ expose :friends_count do |person, options|
+ person.friends.size
+ end
end
class Enterprise < Profile
@@ -316,7 +319,7 @@ module Api
end
expose :params, :if => lambda { |activity, options| activity.kind_of?(ActionTracker::Record)}
expose :content, :if => lambda { |activity, options| activity.kind_of?(Scrap)}
- expose :verb do |activity, options|
+ expose :verb do |activity, options|
activity.kind_of?(Scrap) ? 'leave_scrap' : activity.verb
end
=====================================
test/api/people_test.rb
=====================================
--- a/test/api/people_test.rb
+++ b/test/api/people_test.rb
@@ -369,7 +369,7 @@ class PeopleTest < ActiveSupport::TestCase
assert_equal "www.blog.org", json['person']['additional_data']['Custom Blog']
end
- PERSON_ATTRIBUTES = %w(vote_count comments_count articles_count following_articles_count)
+ PERSON_ATTRIBUTES = %w(vote_count comments_count articles_count following_articles_count friends_count)
PERSON_ATTRIBUTES.map do |attribute|
define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_does_not_contain_the_attribute" do
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/af119b179323bb2daaba064b23880f59229c87b3...2baaf088ed761fd159880f1e89e2cec613ae304f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160905/30ff29c6/attachment-0001.html>
More information about the Noosfero-dev
mailing list