Commit ceddcde8d0d3eaf5adb9bcb4dd5dbe041732bc0c
Exists in
staging
and in
1 other branch
Merge branch 'refactor_profile_description_block_plugin_html_generation' into 'master'
Refactor profile_description_block plugin The view code generation has been moved from the model into a view thus respecting MVC. See merge request !849
Showing
3 changed files
with
28 additions
and
31 deletions
Show diff stats
plugins/profile_description_block/lib/profile_description_block.rb
@@ -16,24 +16,6 @@ class ProfileDescriptionBlock < Block | @@ -16,24 +16,6 @@ class ProfileDescriptionBlock < Block | ||
16 | _('PROFILE DESCRIPTION') | 16 | _('PROFILE DESCRIPTION') |
17 | end | 17 | end |
18 | 18 | ||
19 | - def content(args={}) | ||
20 | - description = if self.owner.description.blank? | ||
21 | - "Description field is empty or | ||
22 | - not enabled on enviroment" | ||
23 | - else | ||
24 | - self.owner.description | ||
25 | - end | ||
26 | - block = self | ||
27 | - s = show_name | ||
28 | - proc do | ||
29 | - render( | ||
30 | - :file => 'blocks/profile_description', | ||
31 | - :locals => { :block => block, :show_name => s , | ||
32 | - :description => description} | ||
33 | - ) | ||
34 | - end | ||
35 | - end | ||
36 | - | ||
37 | def cacheable? | 19 | def cacheable? |
38 | false | 20 | false |
39 | end | 21 | end |
plugins/profile_description_block/test/unit/profile_description_block_test.rb
1 | require 'test_helper' | 1 | require 'test_helper' |
2 | 2 | ||
3 | class ProfileDescriptionBlockTest < ActiveSupport::TestCase | 3 | class ProfileDescriptionBlockTest < ActiveSupport::TestCase |
4 | + should 'describe itself' do | ||
5 | + assert_not_equal Block.description, ProfileDescriptionBlock.description | ||
6 | + end | ||
7 | +end | ||
8 | + | ||
9 | +require 'boxes_helper' | ||
10 | + | ||
11 | +class ProfileDescriptionBlockViewTest < ActionView::TestCase | ||
12 | + include BoxesHelper | ||
13 | + | ||
4 | def setup | 14 | def setup |
5 | e = Environment.default | 15 | e = Environment.default |
6 | e.enabled_plugins = ['ProfileDescriptionPlugin'] | 16 | e.enabled_plugins = ['ProfileDescriptionPlugin'] |
@@ -10,20 +20,20 @@ class ProfileDescriptionBlockTest < ActiveSupport::TestCase | @@ -10,20 +20,20 @@ class ProfileDescriptionBlockTest < ActiveSupport::TestCase | ||
10 | :description => "") | 20 | :description => "") |
11 | end | 21 | end |
12 | 22 | ||
13 | - should 'describe itself' do | ||
14 | - assert_not_equal Block.description, ProfileDescriptionBlock.description | ||
15 | - end | ||
16 | - | ||
17 | should "show profile description inside block" do | 23 | should "show profile description inside block" do |
18 | new_block = ProfileDescriptionBlock.create! | 24 | new_block = ProfileDescriptionBlock.create! |
25 | + | ||
19 | @profile.boxes.first.blocks << new_block | 26 | @profile.boxes.first.blocks << new_block |
20 | - block_menssage = "Description field is empty" | ||
21 | - assert (instance_eval(&Block.last.content).include?(block_menssage)), | 27 | + |
28 | + block_message = "Description field is empty" | ||
29 | + assert (render_block_content(Block.last).include?(block_message)), | ||
22 | "description block doesn't show not found description message" | 30 | "description block doesn't show not found description message" |
31 | + | ||
23 | description = "This is an test" | 32 | description = "This is an test" |
24 | @profile.update_attribute("description", description) | 33 | @profile.update_attribute("description", description) |
25 | @profile.save! | 34 | @profile.save! |
26 | - assert (instance_eval(&Block.last.content).include?(description)), | 35 | + |
36 | + assert (render_block_content(Block.last).include?(description)), | ||
27 | "Description block doesn't show profile description" | 37 | "Description block doesn't show profile description" |
28 | end | 38 | end |
29 | end | 39 | end |
plugins/profile_description_block/views/blocks/profile_description.html.erb
1 | <div class = 'profile-description-block'> | 1 | <div class = 'profile-description-block'> |
2 | -<div class = "block-title"> | ||
3 | - <%= block.title %> | ||
4 | -</div> | ||
5 | -<div class = "profile-description-block-title"> | ||
6 | - <%= description %> | ||
7 | -</div> | 2 | + <div class = "block-title"> |
3 | + <%= block.title %> | ||
4 | + </div> | ||
5 | + | ||
6 | + <div class = "profile-description-block-title"> | ||
7 | + <% if block.owner.description.blank? %> | ||
8 | + Description field is empty or not enabled on enviroment | ||
9 | + <% else %> | ||
10 | + <%= block.owner.description %> | ||
11 | + <% end %> | ||
12 | + </div> | ||
8 | </div> | 13 | </div> |