Commit 7a90f562337cf3e3d73dd05df4590a6ed0437fab
Exists in
fix_sign_up_form
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@gmail.com> See merge request !1000
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
plugins/profile_description_block/lib/profile_description_block.rb
... | ... | @@ -16,6 +16,12 @@ class ProfileDescriptionBlock < Block |
16 | 16 | _('PROFILE DESCRIPTION') |
17 | 17 | end |
18 | 18 | |
19 | + def api_content | |
20 | + description = self.owner.description.present? ? self.owner.description : _("Description field is empty or not enabled on enviroment") | |
21 | + hash = { description: description } | |
22 | + Grape::Presenters::Presenter.represent(hash).as_json | |
23 | + end | |
24 | + | |
19 | 25 | def cacheable? |
20 | 26 | false |
21 | 27 | end | ... | ... |
plugins/profile_description_block/test/unit/profile_description_block_test.rb
... | ... | @@ -36,4 +36,17 @@ class ProfileDescriptionBlockViewTest < ActionView::TestCase |
36 | 36 | assert (render_block_content(Block.last).include?(description)), |
37 | 37 | "Description block doesn't show profile description" |
38 | 38 | end |
39 | + | |
40 | + should 'return profile description in api_content when description is present' do | |
41 | + block = ProfileDescriptionBlock.new | |
42 | + @person.stubs(:description).returns("This is my description").returns("This is my description") | |
43 | + block.stubs(:owner).returns(@person) | |
44 | + assert_equal "This is my description", block.api_content['description'] | |
45 | + end | |
46 | + | |
47 | + should 'return default message in api_content when description is not present' do | |
48 | + block = ProfileDescriptionBlock.new | |
49 | + block.stubs(:owner).returns(@person) | |
50 | + assert_equal "Description field is empty or not enabled on enviroment", block.api_content['description'] | |
51 | + end | |
39 | 52 | end | ... | ... |