Commit 10294f9be50b3a3704cc8ee8d6a1aa2b9ef8521b

Authored by Victor Costa
1 parent 5179b71b

Functional tests for container block

plugins/container_block/controllers/container_block_plugin_controller.rb
... ... @@ -3,14 +3,15 @@ module ContainerBlockPluginController
3 3 def saveWidths
4 4 container = boxes_holder.blocks.find(params[:id])
5 5 pairs = params[:widths].split('|')
6   - settings = {}
  6 + settings = container.children_settings
7 7 pairs.each do |pair|
8 8 id, width = pair.split(',')
9   - settings[id.to_i] = {:width => width}
  9 + settings[id.to_i] = {:width => width.to_i}
10 10 end
11 11 container.children_settings = settings
12 12 container.save!
13   - render :json => {:ok => true}
  13 +
  14 + render :text => _('Block successfully saved.')
14 15 end
15 16  
16 17 end
... ...
plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginAdminControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + Environment.delete_all
  7 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  8 + @environment.enabled_plugins = ['ContainerBlock']
  9 + @environment.save!
  10 +
  11 + user = create_user('testinguser')
  12 + @environment.add_admin(user.person)
  13 + login_as(user.login)
  14 +
  15 + @block = ContainerBlock.create!(:box => @environment.boxes.first)
  16 + @child1 = Block.create!(:box => @block.container_box)
  17 + @child2 = Block.create!(:box => @block.container_box)
  18 + end
  19 +
  20 + should 'save widths of container block children' do
  21 + xhr :post, :saveWidths, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  22 + assert_response 200
  23 + assert_equal 'Block successfully saved.', @response.body
  24 + @block.reload
  25 + assert_equal 100, @block.child_width(@child1.id)
  26 + assert_equal 200, @block.child_width(@child2.id)
  27 + end
  28 +
  29 +end
... ...
plugins/container_block/test/functional/container_block_plugin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginControllerTest < ActionController::TestCase
  4 +
  5 + include ContainerBlockPluginController
  6 +
  7 + def setup
  8 + Environment.delete_all
  9 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  10 + @environment.enabled_plugins = ['ContainerBlock']
  11 + @environment.save!
  12 +
  13 + user = create_user('testinguser')
  14 + @environment.add_admin(user.person)
  15 + login_as(user.login)
  16 +
  17 + @block = ContainerBlock.create!(:box => @environment.boxes.first)
  18 + @child1 = Block.create!(:box => @block.container_box)
  19 + @child2 = Block.create!(:box => @block.container_box)
  20 + @environment = Environment.find(@environment.id)
  21 + stubs(:boxes_holder).returns(@environment)
  22 + @params = {}
  23 + end
  24 +
  25 + attr_reader :params
  26 +
  27 + should 'save widths of container block children' do
  28 + @params = {:id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"}
  29 + expects(:render).with(:text => 'Block successfully saved.')
  30 + saveWidths
  31 + @block.reload
  32 + assert_equal 100, @block.child_width(@child1.id)
  33 + assert_equal 200, @block.child_width(@child2.id)
  34 + end
  35 +
  36 + should 'do not change child width that is not passed in widths param' do
  37 + @block.children_settings = {@child2.id => {:width => 200}}
  38 + @block.save!
  39 + @params = {:id => @block.id, :widths => "#{@child1.id},100"}
  40 + expects(:render).with(:text => 'Block successfully saved.')
  41 + saveWidths
  42 + @block.reload
  43 + assert_equal 100, @block.child_width(@child1.id)
  44 + assert_equal 200, @block.child_width(@child2.id)
  45 + end
  46 +
  47 +end
... ...
plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginMyprofileControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + user = create_user('testinguser')
  7 + login_as(user.login)
  8 +
  9 + @profile = fast_create(Community)
  10 + @profile.add_admin(user.person)
  11 + @box = Box.new(:owner => @profile)
  12 +
  13 + @block = ContainerBlock.create!(:box => @box)
  14 + @child1 = Block.create!(:box => @block.container_box)
  15 + @child2 = Block.create!(:box => @block.container_box)
  16 + end
  17 +
  18 + should 'save widths of container block children' do
  19 + xhr :post, :saveWidths, :profile => @profile.identifier, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  20 + assert_response 200
  21 + assert_equal 'Block successfully saved.', @response.body
  22 + @block.reload
  23 + assert_equal 100, @block.child_width(@child1.id)
  24 + assert_equal 200, @block.child_width(@child2.id)
  25 + end
  26 +
  27 +end
... ...
plugins/container_block/views/blocks/container.rhtml
... ... @@ -16,7 +16,8 @@
16 16 :with => "containerChildrenWidth(#{block.id})",
17 17 :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}" },
18 18 :loading => "open_loading(DEFAULT_LOADING_MESSAGE);",
19   - :loaded => "close_loading();" %>
  19 + :loaded => "close_loading();",
  20 + :complete => "display_notice(request.responseText);"%>
20 21 </div>
21 22  
22 23 <script>
... ...