[Git][noosfero/noosfero][master] 2 commits: friends_block: return api_content with friends list
Leandro Nunes
gitlab at mg.gitlab.com
Wed Feb 1 18:00:55 BRST 2017
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
20caf681 by Victor Costa at 2017-01-27T08:30:11-03:00
friends_block: return api_content with friends list
- - - - -
733838f8 by Leandro Nunes at 2017-02-01T20:00:52+00:00
Merge branch 'friends-block-api' into 'master'
friends_block: return api_content with friends list
See merge request !1102
- - - - -
2 changed files:
- plugins/people_block/lib/friends_block.rb
- plugins/people_block/test/unit/friends_block_test.rb
Changes:
=====================================
plugins/people_block/lib/friends_block.rb
=====================================
--- a/plugins/people_block/lib/friends_block.rb
+++ b/plugins/people_block/lib/friends_block.rb
@@ -24,4 +24,9 @@ class FriendsBlock < PeopleBlockBase
{ :profile => [:profile] }
end
+ def api_content
+ content = Api::Entities::Person.represent(profiles.limit(self.limit)).as_json
+ content['#'] = profiles.size
+ content
+ end
end
=====================================
plugins/people_block/test/unit/friends_block_test.rb
=====================================
--- a/plugins/people_block/test/unit/friends_block_test.rb
+++ b/plugins/people_block/test/unit/friends_block_test.rb
@@ -192,4 +192,28 @@ class FriendsBlockViewTest < ActionView::TestCase
assert a1 > a2*NON_LINEAR_FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{NON_LINEAR_FACTOR}"
end
+ should 'list friends in api content' do
+ owner = fast_create(Person)
+ friend1 = fast_create(Person)
+ friend2 = fast_create(Person)
+ owner.add_friend(friend1)
+ owner.add_friend(friend2)
+ block = FriendsBlock.new
+ block.expects(:owner).returns(owner).at_least_once
+ json = block.api_content
+ assert_equivalent [friend1.identifier, friend2.identifier], json["people"].map {|p| p[:identifier]}
+ end
+
+ should 'limit friends list in api content' do
+ owner = fast_create(Person)
+ 5.times do
+ friend = fast_create(Person)
+ owner.add_friend(friend)
+ end
+ block = FriendsBlock.new(limit: 3)
+ block.expects(:owner).returns(owner.reload).at_least_once
+ json = block.api_content
+ assert_equal 3, json["people"].size
+ assert_equal 5, json["#"]
+ end
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/244ac940ee083a3ffe212ff672540d3a7ad3004c...733838f89cd85094b0f772394a95303129e3479f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170201/0d7c5946/attachment-0001.html>
More information about the Noosfero-dev
mailing list