Commit 4074bc1b6d993430cf2eeff9494627ada23f1efd
1 parent
27c9021e
Exists in
master
and in
29 other branches
Added tests to container block pugin
Showing
7 changed files
with
75 additions
and
16 deletions
Show diff stats
plugins/container_block/lib/container_block.rb
| @@ -14,7 +14,7 @@ class ContainerBlock < Block | @@ -14,7 +14,7 @@ class ContainerBlock < Block | ||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | def layout_template | 16 | def layout_template |
| 17 | - 'default' | 17 | + nil |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | def create_box | 20 | def create_box |
| @@ -39,7 +39,6 @@ class ContainerBlock < Block | @@ -39,7 +39,6 @@ class ContainerBlock < Block | ||
| 39 | children_settings[child_id][:width] if children_settings[child_id] | 39 | children_settings[child_id][:width] if children_settings[child_id] |
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | - #FIXME controller test | ||
| 43 | def content(args={}) | 42 | def content(args={}) |
| 44 | block = self | 43 | block = self |
| 45 | lambda do | 44 | lambda do |
plugins/container_block/test/functional/container_block_environment_design_controller_test.rb
| 1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | ||
| 3 | # Re-raise errors caught by the controller. | 3 | # Re-raise errors caught by the controller. |
| 4 | -class EnvironmentDesignController; def rescue_action(e) raise e end; end | 4 | +class EnvironmentDesignController |
| 5 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | ||
| 6 | + def rescue_action(e) | ||
| 7 | + raise e | ||
| 8 | + end | ||
| 9 | +end | ||
| 5 | 10 | ||
| 6 | class EnvironmentDesignControllerTest < ActionController::TestCase | 11 | class EnvironmentDesignControllerTest < ActionController::TestCase |
| 7 | 12 | ||
| @@ -15,8 +20,8 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -15,8 +20,8 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
| 15 | @environment.add_admin(user.person) | 20 | @environment.add_admin(user.person) |
| 16 | login_as(user.login) | 21 | login_as(user.login) |
| 17 | 22 | ||
| 18 | - box = Box.create!(:owner => @environment) | ||
| 19 | - @block = ContainerBlock.create!(:box => box) | 23 | + @block = ContainerBlock.create!(:box => @environment.boxes.first) |
| 24 | + @environment = Environment.find(@environment.id) | ||
| 20 | end | 25 | end |
| 21 | 26 | ||
| 22 | should 'be able to edit ContainerBlock' do | 27 | should 'be able to edit ContainerBlock' do |
| @@ -31,4 +36,22 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -31,4 +36,22 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
| 31 | assert_equal 'Container', @block.title | 36 | assert_equal 'Container', @block.title |
| 32 | end | 37 | end |
| 33 | 38 | ||
| 39 | + should 'display container children' do | ||
| 40 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') | ||
| 41 | + get :index | ||
| 42 | + assert_tag :div, :attributes => { :id => "block-#{c1.id}" } | ||
| 43 | + end | ||
| 44 | + | ||
| 45 | + should 'display hidden children of container block' do | ||
| 46 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never') | ||
| 47 | + get :index | ||
| 48 | + assert_tag :div, :attributes => { :id => "block-#{c1.id}", :class => 'block raw-html-block invisible-block' } | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + should 'display button to save widths of container children' do | ||
| 52 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') | ||
| 53 | + get :index | ||
| 54 | + assert_tag :a, :attributes => { :class => "button icon-save container_block_save" } | ||
| 55 | + end | ||
| 56 | + | ||
| 34 | end | 57 | end |
plugins/container_block/test/functional/container_block_home_controller_test.rb
| @@ -31,4 +31,31 @@ class HomeControllerTest < ActionController::TestCase | @@ -31,4 +31,31 @@ class HomeControllerTest < ActionController::TestCase | ||
| 31 | assert_tag :div, :attributes => { :class => 'block container-block' } | 31 | assert_tag :div, :attributes => { :class => 'block container-block' } |
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | + should 'display container children' do | ||
| 35 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') | ||
| 36 | + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content') | ||
| 37 | + get :index | ||
| 38 | + assert_tag :div, :attributes => { :id => "block-#{c1.id}" } | ||
| 39 | + assert_tag :div, :attributes => { :id => "block-#{c2.id}" } | ||
| 40 | + end | ||
| 41 | + | ||
| 42 | + should 'display style tags for container children' do | ||
| 43 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') | ||
| 44 | + @block.children_settings = { c1.id => {:width => "123"} } | ||
| 45 | + @block.save! | ||
| 46 | + get :index | ||
| 47 | + assert_match /#block-#{c1.id} \{ width: 123px; \}/, @response.body | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + should 'do not display hidden children of container' do | ||
| 51 | + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never') | ||
| 52 | + get :index | ||
| 53 | + assert_no_tag :div, :attributes => { :id => "block-#{c1.id}" } | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + should 'do not display button to save widths of container children' do | ||
| 57 | + get :index | ||
| 58 | + assert_no_tag :a, :attributes => { :class => "button icon-save container_block_save" } | ||
| 59 | + end | ||
| 60 | + | ||
| 34 | end | 61 | end |
plugins/container_block/test/unit/container_block_test.rb
| @@ -65,4 +65,8 @@ class ContainerBlockTest < ActiveSupport::TestCase | @@ -65,4 +65,8 @@ class ContainerBlockTest < ActiveSupport::TestCase | ||
| 65 | assert_equal nil, @block.child_width(1) | 65 | assert_equal nil, @block.child_width(1) |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | + should 'return nil at layout_templat' do | ||
| 69 | + assert_equal nil, @block.layout_template | ||
| 70 | + end | ||
| 71 | + | ||
| 68 | end | 72 | end |
plugins/container_block/test/unit/environment_test.rb
| @@ -8,22 +8,25 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -8,22 +8,25 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 8 | @box = Box.create!(:owner => @environment) | 8 | @box = Box.create!(:owner => @environment) |
| 9 | @block = Block.create!(:box => @box) | 9 | @block = Block.create!(:box => @box) |
| 10 | 10 | ||
| 11 | - @container_box = Box.create!(:owner => @environment) | ||
| 12 | - @container = ContainerBlock.create!(:box => @container_box) | 11 | + @container = ContainerBlock.create!(:box => @box) |
| 13 | end | 12 | end |
| 14 | 13 | ||
| 15 | should 'return blocks as usual' do | 14 | should 'return blocks as usual' do |
| 16 | assert_equal [@block, @container], @environment.blocks | 15 | assert_equal [@block, @container], @environment.blocks |
| 17 | end | 16 | end |
| 18 | 17 | ||
| 18 | + should 'return blocks with container children' do | ||
| 19 | + child = Block.create!(:box => @container.container_box) | ||
| 20 | + assert_equal [@block, @container, child], @environment.blocks | ||
| 21 | + end | ||
| 22 | + | ||
| 19 | should 'return block with id at find method' do | 23 | should 'return block with id at find method' do |
| 20 | assert_equal @block, @environment.blocks.find(@block.id) | 24 | assert_equal @block, @environment.blocks.find(@block.id) |
| 21 | end | 25 | end |
| 22 | 26 | ||
| 23 | should 'return child block with id at find method' do | 27 | should 'return child block with id at find method' do |
| 24 | - block = Block.create!(:box => @container_box) | ||
| 25 | - @container.save! | ||
| 26 | - assert_equal @block, @environment.blocks.find(@block.id) | 28 | + child = Block.create!(:box => @container.container_box) |
| 29 | + assert_equal child, @environment.blocks.find(child.id) | ||
| 27 | end | 30 | end |
| 28 | 31 | ||
| 29 | end | 32 | end |
plugins/container_block/test/unit/profile_test.rb
| @@ -8,22 +8,25 @@ class ProfileTest < ActiveSupport::TestCase | @@ -8,22 +8,25 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 8 | @box = Box.create!(:owner => @profile) | 8 | @box = Box.create!(:owner => @profile) |
| 9 | @block = Block.create!(:box => @box) | 9 | @block = Block.create!(:box => @box) |
| 10 | 10 | ||
| 11 | - @container_box = Box.create!(:owner => @profile) | ||
| 12 | - @container = ContainerBlock.create!(:box => @container_box) | 11 | + @container = ContainerBlock.create!(:box => @box) |
| 13 | end | 12 | end |
| 14 | 13 | ||
| 15 | should 'return blocks as usual' do | 14 | should 'return blocks as usual' do |
| 16 | assert_equal [@block, @container], @profile.blocks | 15 | assert_equal [@block, @container], @profile.blocks |
| 17 | end | 16 | end |
| 18 | 17 | ||
| 18 | + should 'return blocks with container children' do | ||
| 19 | + child = Block.create!(:box => @container.container_box) | ||
| 20 | + assert_equal [@block, @container, child], @profile.blocks | ||
| 21 | + end | ||
| 22 | + | ||
| 19 | should 'return block with id at find method' do | 23 | should 'return block with id at find method' do |
| 20 | assert_equal @block, @profile.blocks.find(@block.id) | 24 | assert_equal @block, @profile.blocks.find(@block.id) |
| 21 | end | 25 | end |
| 22 | 26 | ||
| 23 | should 'return child block with id at find method' do | 27 | should 'return child block with id at find method' do |
| 24 | - block = Block.create!(:box => @container_box) | ||
| 25 | - @container.save! | ||
| 26 | - assert_equal @block, @profile.blocks.find(@block.id) | 28 | + child = Block.create!(:box => @container.container_box) |
| 29 | + assert_equal child, @profile.blocks.find(child.id) | ||
| 27 | end | 30 | end |
| 28 | 31 | ||
| 29 | end | 32 | end |
plugins/container_block/views/blocks/container.rhtml
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | 11 | ||
| 12 | <% if edit_mode %> | 12 | <% if edit_mode %> |
| 13 | <div class="button-bar"> | 13 | <div class="button-bar"> |
| 14 | - <%= link_to_remote '', :url => { :controller => @controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id }, :with => "containerChildrenWidth(#{block.id})", :html => {:class => "button icon-save" } %> | 14 | + <%= link_to_remote '', :url => { :controller => @controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id }, :with => "containerChildrenWidth(#{block.id})", :html => {:class => "button icon-save container_block_save" } %> |
| 15 | </div> | 15 | </div> |
| 16 | 16 | ||
| 17 | <script> | 17 | <script> |