diff --git a/plugins/container_block/controllers/container_block_plugin_controller.rb b/plugins/container_block/controllers/container_block_plugin_controller.rb index b336571..df02cdc 100644 --- a/plugins/container_block/controllers/container_block_plugin_controller.rb +++ b/plugins/container_block/controllers/container_block_plugin_controller.rb @@ -3,14 +3,15 @@ module ContainerBlockPluginController def saveWidths container = boxes_holder.blocks.find(params[:id]) pairs = params[:widths].split('|') - settings = {} + settings = container.children_settings pairs.each do |pair| id, width = pair.split(',') - settings[id.to_i] = {:width => width} + settings[id.to_i] = {:width => width.to_i} end container.children_settings = settings container.save! - render :json => {:ok => true} + + render :text => _('Block successfully saved.') end end diff --git a/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb new file mode 100644 index 0000000..c6c5c19 --- /dev/null +++ b/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContainerBlockPluginAdminControllerTest < ActionController::TestCase + + def setup + Environment.delete_all + @environment = Environment.new(:name => 'testenv', :is_default => true) + @environment.enabled_plugins = ['ContainerBlock'] + @environment.save! + + user = create_user('testinguser') + @environment.add_admin(user.person) + login_as(user.login) + + @block = ContainerBlock.create!(:box => @environment.boxes.first) + @child1 = Block.create!(:box => @block.container_box) + @child2 = Block.create!(:box => @block.container_box) + end + + should 'save widths of container block children' do + xhr :post, :saveWidths, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200" + assert_response 200 + assert_equal 'Block successfully saved.', @response.body + @block.reload + assert_equal 100, @block.child_width(@child1.id) + assert_equal 200, @block.child_width(@child2.id) + end + +end diff --git a/plugins/container_block/test/functional/container_block_plugin_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_controller_test.rb new file mode 100644 index 0000000..0c672b3 --- /dev/null +++ b/plugins/container_block/test/functional/container_block_plugin_controller_test.rb @@ -0,0 +1,47 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContainerBlockPluginControllerTest < ActionController::TestCase + + include ContainerBlockPluginController + + def setup + Environment.delete_all + @environment = Environment.new(:name => 'testenv', :is_default => true) + @environment.enabled_plugins = ['ContainerBlock'] + @environment.save! + + user = create_user('testinguser') + @environment.add_admin(user.person) + login_as(user.login) + + @block = ContainerBlock.create!(:box => @environment.boxes.first) + @child1 = Block.create!(:box => @block.container_box) + @child2 = Block.create!(:box => @block.container_box) + @environment = Environment.find(@environment.id) + stubs(:boxes_holder).returns(@environment) + @params = {} + end + + attr_reader :params + + should 'save widths of container block children' do + @params = {:id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"} + expects(:render).with(:text => 'Block successfully saved.') + saveWidths + @block.reload + assert_equal 100, @block.child_width(@child1.id) + assert_equal 200, @block.child_width(@child2.id) + end + + should 'do not change child width that is not passed in widths param' do + @block.children_settings = {@child2.id => {:width => 200}} + @block.save! + @params = {:id => @block.id, :widths => "#{@child1.id},100"} + expects(:render).with(:text => 'Block successfully saved.') + saveWidths + @block.reload + assert_equal 100, @block.child_width(@child1.id) + assert_equal 200, @block.child_width(@child2.id) + end + +end diff --git a/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..8df50f0 --- /dev/null +++ b/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb @@ -0,0 +1,27 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContainerBlockPluginMyprofileControllerTest < ActionController::TestCase + + def setup + user = create_user('testinguser') + login_as(user.login) + + @profile = fast_create(Community) + @profile.add_admin(user.person) + @box = Box.new(:owner => @profile) + + @block = ContainerBlock.create!(:box => @box) + @child1 = Block.create!(:box => @block.container_box) + @child2 = Block.create!(:box => @block.container_box) + end + + should 'save widths of container block children' do + xhr :post, :saveWidths, :profile => @profile.identifier, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200" + assert_response 200 + assert_equal 'Block successfully saved.', @response.body + @block.reload + assert_equal 100, @block.child_width(@child1.id) + assert_equal 200, @block.child_width(@child2.id) + end + +end diff --git a/plugins/container_block/views/blocks/container.rhtml b/plugins/container_block/views/blocks/container.rhtml index 2cabf62..6ec0ee9 100644 --- a/plugins/container_block/views/blocks/container.rhtml +++ b/plugins/container_block/views/blocks/container.rhtml @@ -16,7 +16,8 @@ :with => "containerChildrenWidth(#{block.id})", :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}" }, :loading => "open_loading(DEFAULT_LOADING_MESSAGE);", - :loaded => "close_loading();" %> + :loaded => "close_loading();", + :complete => "display_notice(request.responseText);"%>