Commit 6e1240a6d8fa08b7b8b2d06292908680f89327f7
1 parent
038c04ea
Exists in
staging
and in
4 other branches
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>
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,6 +16,12 @@ class ProfileDescriptionBlock < Block | ||
| 16 | _('PROFILE DESCRIPTION') | 16 | _('PROFILE DESCRIPTION') |
| 17 | end | 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 | def cacheable? | 25 | def cacheable? |
| 20 | false | 26 | false |
| 21 | end | 27 | end |
plugins/profile_description_block/test/unit/profile_description_block_test.rb
| @@ -36,4 +36,17 @@ class ProfileDescriptionBlockViewTest < ActionView::TestCase | @@ -36,4 +36,17 @@ class ProfileDescriptionBlockViewTest < ActionView::TestCase | ||
| 36 | assert (render_block_content(Block.last).include?(description)), | 36 | assert (render_block_content(Block.last).include?(description)), |
| 37 | "Description block doesn't show profile description" | 37 | "Description block doesn't show profile description" |
| 38 | end | 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 | end | 52 | end |