]> source.dussan.org Git - redmine.git/commitdiff
Merged r11225 from trunk (#12838).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Jan 2013 17:01:03 +0000 (17:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Jan 2013 17:01:03 +0000 (17:01 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.2-stable@11232 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/my_controller.rb
test/functional/my_controller_test.rb

index b2c2a9dc7fc74eb0a4e99e28185e72c20001babe..7a18c503ecd649efaa7e1d9284caade29f9791e0 100644 (file)
@@ -147,15 +147,16 @@ class MyController < ApplicationController
   # params[:block] : id of the block to add
   def add_block
     block = params[:block].to_s.underscore
-    (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
-    @user = User.current
-    layout = @user.pref[:my_page_layout] || {}
-    # remove if already present in a group
-    %w(top left right).each {|f| (layout[f] ||= []).delete block }
-    # add it on top
-    layout['top'].unshift block
-    @user.pref[:my_page_layout] = layout
-    @user.pref.save
+    if block.present? && BLOCKS.key?(block)
+      @user = User.current
+      layout = @user.pref[:my_page_layout] || {}
+      # remove if already present in a group
+      %w(top left right).each {|f| (layout[f] ||= []).delete block }
+      # add it on top
+      layout['top'].unshift block
+      @user.pref[:my_page_layout] = layout
+      @user.pref.save
+    end
     redirect_to :action => 'page_layout'
   end
 
index f5f5f06b1d9bcccf55080bcaf4b3b5e4c17ed8eb..dfc7d6f89cec970758f9e992edef06ed1d0a3be9 100644 (file)
@@ -187,6 +187,11 @@ class MyControllerTest < ActionController::TestCase
     assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
   end
 
+  def test_add_invalid_block_should_redirect
+    post :add_block, :block => 'invalid'
+    assert_redirected_to '/my/page_layout'
+  end
+
   def test_remove_block
     post :remove_block, :block => 'issuesassignedtome'
     assert_redirected_to '/my/page_layout'