@@ -147,15 +147,16 class MyController < ApplicationController | |||
|
147 | 147 | # params[:block] : id of the block to add |
|
148 | 148 | def add_block |
|
149 | 149 | block = params[:block].to_s.underscore |
|
150 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) | |
|
151 | @user = User.current | |
|
152 | layout = @user.pref[:my_page_layout] || {} | |
|
153 | # remove if already present in a group | |
|
154 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
155 | # add it on top | |
|
156 | layout['top'].unshift block | |
|
157 | @user.pref[:my_page_layout] = layout | |
|
158 | @user.pref.save | |
|
150 | if block.present? && BLOCKS.key?(block) | |
|
151 | @user = User.current | |
|
152 | layout = @user.pref[:my_page_layout] || {} | |
|
153 | # remove if already present in a group | |
|
154 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
155 | # add it on top | |
|
156 | layout['top'].unshift block | |
|
157 | @user.pref[:my_page_layout] = layout | |
|
158 | @user.pref.save | |
|
159 | end | |
|
159 | 160 | redirect_to :action => 'page_layout' |
|
160 | 161 | end |
|
161 | 162 |
@@ -187,6 +187,11 class MyControllerTest < ActionController::TestCase | |||
|
187 | 187 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | def test_add_invalid_block_should_redirect | |
|
191 | post :add_block, :block => 'invalid' | |
|
192 | assert_redirected_to '/my/page_layout' | |
|
193 | end | |
|
194 | ||
|
190 | 195 | def test_remove_block |
|
191 | 196 | post :remove_block, :block => 'issuesassignedtome' |
|
192 | 197 | assert_redirected_to '/my/page_layout' |
General Comments 0
You need to be logged in to leave comments.
Login now