[Git][noosfero/noosfero][master] 2 commits: Adds data to profile description block plugin api

Daniela Feitosa gitlab at mg.gitlab.com
Mon Aug 8 10:46:12 BRT 2016


Daniela Feitosa pushed to branch master at Noosfero / noosfero


Commits:
6e1240a6 by Tallys Martins at 2016-08-05T12:30:21-03:00
Adds data to profile description block plugin api

- The block now returns the description of its owner through the api_content
method.

Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
7a90f562 by Daniela Feitosa at 2016-08-08T13:45:59+00:00
Merge branch 'profile_description_block_plugin_api' into 'master'

Adds data to profile description block plugin api

- The block now returns the description of its owner through the api_content
method.

Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

See merge request !1000
- - - - -


2 changed files:

- plugins/profile_description_block/lib/profile_description_block.rb
- plugins/profile_description_block/test/unit/profile_description_block_test.rb


Changes:

=====================================
plugins/profile_description_block/lib/profile_description_block.rb
=====================================
--- a/plugins/profile_description_block/lib/profile_description_block.rb
+++ b/plugins/profile_description_block/lib/profile_description_block.rb
@@ -16,6 +16,12 @@ class ProfileDescriptionBlock < Block
     _('PROFILE DESCRIPTION')
   end
 
+  def api_content
+    description = self.owner.description.present? ? self.owner.description : _("Description field is empty or not enabled on enviroment")
+    hash = { description: description }
+    Grape::Presenters::Presenter.represent(hash).as_json
+  end
+
   def cacheable?
     false
   end


=====================================
plugins/profile_description_block/test/unit/profile_description_block_test.rb
=====================================
--- a/plugins/profile_description_block/test/unit/profile_description_block_test.rb
+++ b/plugins/profile_description_block/test/unit/profile_description_block_test.rb
@@ -36,4 +36,17 @@ class ProfileDescriptionBlockViewTest < ActionView::TestCase
     assert (render_block_content(Block.last).include?(description)),
       "Description block doesn't show profile description"
   end
+
+  should 'return profile description in api_content when description is present' do
+    block = ProfileDescriptionBlock.new
+    @person.stubs(:description).returns("This is my description").returns("This is my description")
+    block.stubs(:owner).returns(@person)
+    assert_equal "This is my description", block.api_content['description']
+  end
+
+  should 'return default message in api_content when description is not present' do
+    block = ProfileDescriptionBlock.new
+    block.stubs(:owner).returns(@person)
+    assert_equal "Description field is empty or not enabled on enviroment", block.api_content['description']
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/e68ef809aca10100a8b846104daf74dcb779489b...7a90f562337cf3e3d73dd05df4590a6ed0437fab
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160808/17033bbc/attachment-0001.html>


More information about the Noosfero-dev mailing list