Commit 6f65bb66ea2061f21dbe49d3b497ad0bd7f265ae

Authored by Rafael Reggiani Manzo
Committed by Rodrigo Souto
1 parent 555c63fe

Refactor profile_description_block plugin

The view code generation has been moved from the model into a view thus
respecting MVC.
plugins/profile_description_block/lib/profile_description_block.rb
... ... @@ -16,24 +16,6 @@ class ProfileDescriptionBlock < Block
16 16 _('PROFILE DESCRIPTION')
17 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 19 def cacheable?
38 20 false
39 21 end
... ...
plugins/profile_description_block/test/unit/profile_description_block_test.rb
1 1 require 'test_helper'
2 2  
3 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 14 def setup
5 15 e = Environment.default
6 16 e.enabled_plugins = ['ProfileDescriptionPlugin']
... ... @@ -10,20 +20,20 @@ class ProfileDescriptionBlockTest &lt; ActiveSupport::TestCase
10 20 :description => "")
11 21 end
12 22  
13   - should 'describe itself' do
14   - assert_not_equal Block.description, ProfileDescriptionBlock.description
15   - end
16   -
17 23 should "show profile description inside block" do
18 24 new_block = ProfileDescriptionBlock.create!
  25 +
19 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 30 "description block doesn't show not found description message"
  31 +
23 32 description = "This is an test"
24 33 @profile.update_attribute("description", description)
25 34 @profile.save!
26   - assert (instance_eval(&Block.last.content).include?(description)),
  35 +
  36 + assert (render_block_content(Block.last).include?(description)),
27 37 "Description block doesn't show profile description"
28 38 end
29 39 end
... ...
plugins/profile_description_block/views/blocks/profile_description.html.erb
1 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 13 </div>
... ...