[Git][noosfero/noosfero][master] 2 commits: communities-block: add api content

Leandro Nunes gitlab at mg.gitlab.com
Mon Feb 13 14:38:57 BRST 2017


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
2e41ec28 by Victor Costa at 2017-02-13T10:29:16-03:00
communities-block: add api content

- - - - -
af661831 by Leandro Nunes at 2017-02-13T16:38:47+00:00
Merge branch 'communites-block-api' into 'master'

communities-block: add api content

See merge request !1112
- - - - -


2 changed files:

- app/models/communities_block.rb
- test/unit/communities_block_test.rb


Changes:

=====================================
app/models/communities_block.rb
=====================================
--- a/app/models/communities_block.rb
+++ b/app/models/communities_block.rb
@@ -31,4 +31,9 @@ class CommunitiesBlock < ProfileListBlock
     owner.communities
   end
 
+  def api_content(params = {})
+    content = Api::Entities::Community.represent(profiles.limit(self.limit)).as_json
+    content['#'] = profiles.size
+    content
+  end
 end


=====================================
test/unit/communities_block_test.rb
=====================================
--- a/test/unit/communities_block_test.rb
+++ b/test/unit/communities_block_test.rb
@@ -92,4 +92,29 @@ class CommunitiesBlockViewTest < ActionView::TestCase
 
     assert_equal '', render_block_footer(block)
   end
+
+  should 'list communities in api content' do
+    owner = fast_create(Person)
+    community1 = fast_create(Community)
+    community2 = fast_create(Community)
+    community1.add_member(owner)
+    community2.add_member(owner)
+    block = CommunitiesBlock.new
+    block.expects(:owner).returns(owner).at_least_once
+    json = block.api_content
+    assert_equivalent [community1.identifier, community2.identifier], json["communities"].map {|p| p[:identifier]}
+  end
+
+  should 'limit communities list in api content' do
+    owner = fast_create(Person)
+    5.times do
+      community = fast_create(Community)
+      community.add_member(owner)
+    end
+    block = CommunitiesBlock.new(limit: 3)
+    block.expects(:owner).returns(owner.reload).at_least_once
+    json = block.api_content
+    assert_equal 3, json["communities"].size
+    assert_equal 5, json["#"]
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/ff84efb0798d280cbf41eb8328871f27773ca5aa...af6618310ad3afe325b9115a00dc1fdc9ad7e95a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170213/a4618637/attachment-0001.html>


More information about the Noosfero-dev mailing list