##// END OF EJS Templates
Fixed that adding a blank/invalid block to my page renders a blank page (#12838)....
Jean-Philippe Lang -
r10995:6e6ce7c08595
parent child
Show More
@@ -1,197 +1,198
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class MyController < ApplicationController
18 class MyController < ApplicationController
19 before_filter :require_login
19 before_filter :require_login
20
20
21 helper :issues
21 helper :issues
22 helper :users
22 helper :users
23 helper :custom_fields
23 helper :custom_fields
24
24
25 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
26 'issuesreportedbyme' => :label_reported_issues,
26 'issuesreportedbyme' => :label_reported_issues,
27 'issueswatched' => :label_watched_issues,
27 'issueswatched' => :label_watched_issues,
28 'news' => :label_news_latest,
28 'news' => :label_news_latest,
29 'calendar' => :label_calendar,
29 'calendar' => :label_calendar,
30 'documents' => :label_document_plural,
30 'documents' => :label_document_plural,
31 'timelog' => :label_spent_time
31 'timelog' => :label_spent_time
32 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
32 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
33
33
34 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
34 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
35 'right' => ['issuesreportedbyme']
35 'right' => ['issuesreportedbyme']
36 }.freeze
36 }.freeze
37
37
38 def index
38 def index
39 page
39 page
40 render :action => 'page'
40 render :action => 'page'
41 end
41 end
42
42
43 # Show user's page
43 # Show user's page
44 def page
44 def page
45 @user = User.current
45 @user = User.current
46 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
46 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
47 end
47 end
48
48
49 # Edit user's account
49 # Edit user's account
50 def account
50 def account
51 @user = User.current
51 @user = User.current
52 @pref = @user.pref
52 @pref = @user.pref
53 if request.post?
53 if request.post?
54 @user.safe_attributes = params[:user]
54 @user.safe_attributes = params[:user]
55 @user.pref.attributes = params[:pref]
55 @user.pref.attributes = params[:pref]
56 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
56 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
57 if @user.save
57 if @user.save
58 @user.pref.save
58 @user.pref.save
59 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
59 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
60 set_language_if_valid @user.language
60 set_language_if_valid @user.language
61 flash[:notice] = l(:notice_account_updated)
61 flash[:notice] = l(:notice_account_updated)
62 redirect_to my_account_path
62 redirect_to my_account_path
63 return
63 return
64 end
64 end
65 end
65 end
66 end
66 end
67
67
68 # Destroys user's account
68 # Destroys user's account
69 def destroy
69 def destroy
70 @user = User.current
70 @user = User.current
71 unless @user.own_account_deletable?
71 unless @user.own_account_deletable?
72 redirect_to my_account_path
72 redirect_to my_account_path
73 return
73 return
74 end
74 end
75
75
76 if request.post? && params[:confirm]
76 if request.post? && params[:confirm]
77 @user.destroy
77 @user.destroy
78 if @user.destroyed?
78 if @user.destroyed?
79 logout_user
79 logout_user
80 flash[:notice] = l(:notice_account_deleted)
80 flash[:notice] = l(:notice_account_deleted)
81 end
81 end
82 redirect_to home_path
82 redirect_to home_path
83 end
83 end
84 end
84 end
85
85
86 # Manage user's password
86 # Manage user's password
87 def password
87 def password
88 @user = User.current
88 @user = User.current
89 unless @user.change_password_allowed?
89 unless @user.change_password_allowed?
90 flash[:error] = l(:notice_can_t_change_password)
90 flash[:error] = l(:notice_can_t_change_password)
91 redirect_to my_account_path
91 redirect_to my_account_path
92 return
92 return
93 end
93 end
94 if request.post?
94 if request.post?
95 if @user.check_password?(params[:password])
95 if @user.check_password?(params[:password])
96 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
96 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
97 if @user.save
97 if @user.save
98 flash[:notice] = l(:notice_account_password_updated)
98 flash[:notice] = l(:notice_account_password_updated)
99 redirect_to my_account_path
99 redirect_to my_account_path
100 end
100 end
101 else
101 else
102 flash[:error] = l(:notice_account_wrong_password)
102 flash[:error] = l(:notice_account_wrong_password)
103 end
103 end
104 end
104 end
105 end
105 end
106
106
107 # Create a new feeds key
107 # Create a new feeds key
108 def reset_rss_key
108 def reset_rss_key
109 if request.post?
109 if request.post?
110 if User.current.rss_token
110 if User.current.rss_token
111 User.current.rss_token.destroy
111 User.current.rss_token.destroy
112 User.current.reload
112 User.current.reload
113 end
113 end
114 User.current.rss_key
114 User.current.rss_key
115 flash[:notice] = l(:notice_feeds_access_key_reseted)
115 flash[:notice] = l(:notice_feeds_access_key_reseted)
116 end
116 end
117 redirect_to my_account_path
117 redirect_to my_account_path
118 end
118 end
119
119
120 # Create a new API key
120 # Create a new API key
121 def reset_api_key
121 def reset_api_key
122 if request.post?
122 if request.post?
123 if User.current.api_token
123 if User.current.api_token
124 User.current.api_token.destroy
124 User.current.api_token.destroy
125 User.current.reload
125 User.current.reload
126 end
126 end
127 User.current.api_key
127 User.current.api_key
128 flash[:notice] = l(:notice_api_access_key_reseted)
128 flash[:notice] = l(:notice_api_access_key_reseted)
129 end
129 end
130 redirect_to my_account_path
130 redirect_to my_account_path
131 end
131 end
132
132
133 # User's page layout configuration
133 # User's page layout configuration
134 def page_layout
134 def page_layout
135 @user = User.current
135 @user = User.current
136 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
136 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
137 @block_options = []
137 @block_options = []
138 BLOCKS.each do |k, v|
138 BLOCKS.each do |k, v|
139 unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
139 unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
140 @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
140 @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
141 end
141 end
142 end
142 end
143 end
143 end
144
144
145 # Add a block to user's page
145 # Add a block to user's page
146 # The block is added on top of the page
146 # The block is added on top of the page
147 # params[:block] : id of the block to add
147 # params[:block] : id of the block to add
148 def add_block
148 def add_block
149 block = params[:block].to_s.underscore
149 block = params[:block].to_s.underscore
150 (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
150 if block.present? && BLOCKS.key?(block)
151 @user = User.current
151 @user = User.current
152 layout = @user.pref[:my_page_layout] || {}
152 layout = @user.pref[:my_page_layout] || {}
153 # remove if already present in a group
153 # remove if already present in a group
154 %w(top left right).each {|f| (layout[f] ||= []).delete block }
154 %w(top left right).each {|f| (layout[f] ||= []).delete block }
155 # add it on top
155 # add it on top
156 layout['top'].unshift block
156 layout['top'].unshift block
157 @user.pref[:my_page_layout] = layout
157 @user.pref[:my_page_layout] = layout
158 @user.pref.save
158 @user.pref.save
159 end
159 redirect_to my_page_layout_path
160 redirect_to my_page_layout_path
160 end
161 end
161
162
162 # Remove a block to user's page
163 # Remove a block to user's page
163 # params[:block] : id of the block to remove
164 # params[:block] : id of the block to remove
164 def remove_block
165 def remove_block
165 block = params[:block].to_s.underscore
166 block = params[:block].to_s.underscore
166 @user = User.current
167 @user = User.current
167 # remove block in all groups
168 # remove block in all groups
168 layout = @user.pref[:my_page_layout] || {}
169 layout = @user.pref[:my_page_layout] || {}
169 %w(top left right).each {|f| (layout[f] ||= []).delete block }
170 %w(top left right).each {|f| (layout[f] ||= []).delete block }
170 @user.pref[:my_page_layout] = layout
171 @user.pref[:my_page_layout] = layout
171 @user.pref.save
172 @user.pref.save
172 redirect_to my_page_layout_path
173 redirect_to my_page_layout_path
173 end
174 end
174
175
175 # Change blocks order on user's page
176 # Change blocks order on user's page
176 # params[:group] : group to order (top, left or right)
177 # params[:group] : group to order (top, left or right)
177 # params[:list-(top|left|right)] : array of block ids of the group
178 # params[:list-(top|left|right)] : array of block ids of the group
178 def order_blocks
179 def order_blocks
179 group = params[:group]
180 group = params[:group]
180 @user = User.current
181 @user = User.current
181 if group.is_a?(String)
182 if group.is_a?(String)
182 group_items = (params["blocks"] || []).collect(&:underscore)
183 group_items = (params["blocks"] || []).collect(&:underscore)
183 group_items.each {|s| s.sub!(/^block_/, '')}
184 group_items.each {|s| s.sub!(/^block_/, '')}
184 if group_items and group_items.is_a? Array
185 if group_items and group_items.is_a? Array
185 layout = @user.pref[:my_page_layout] || {}
186 layout = @user.pref[:my_page_layout] || {}
186 # remove group blocks if they are presents in other groups
187 # remove group blocks if they are presents in other groups
187 %w(top left right).each {|f|
188 %w(top left right).each {|f|
188 layout[f] = (layout[f] || []) - group_items
189 layout[f] = (layout[f] || []) - group_items
189 }
190 }
190 layout[group] = group_items
191 layout[group] = group_items
191 @user.pref[:my_page_layout] = layout
192 @user.pref[:my_page_layout] = layout
192 @user.pref.save
193 @user.pref.save
193 end
194 end
194 end
195 end
195 render :nothing => true
196 render :nothing => true
196 end
197 end
197 end
198 end
@@ -1,243 +1,248
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class MyControllerTest < ActionController::TestCase
20 class MyControllerTest < ActionController::TestCase
21 fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
21 fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
22 :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
22 :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
23
23
24 def setup
24 def setup
25 @request.session[:user_id] = 2
25 @request.session[:user_id] = 2
26 end
26 end
27
27
28 def test_index
28 def test_index
29 get :index
29 get :index
30 assert_response :success
30 assert_response :success
31 assert_template 'page'
31 assert_template 'page'
32 end
32 end
33
33
34 def test_page
34 def test_page
35 get :page
35 get :page
36 assert_response :success
36 assert_response :success
37 assert_template 'page'
37 assert_template 'page'
38 end
38 end
39
39
40 def test_page_with_timelog_block
40 def test_page_with_timelog_block
41 preferences = User.find(2).pref
41 preferences = User.find(2).pref
42 preferences[:my_page_layout] = {'top' => ['timelog']}
42 preferences[:my_page_layout] = {'top' => ['timelog']}
43 preferences.save!
43 preferences.save!
44 TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10)
44 TimeEntry.create!(:user => User.find(2), :spent_on => Date.yesterday, :issue_id => 1, :hours => 2.5, :activity_id => 10)
45
45
46 get :page
46 get :page
47 assert_response :success
47 assert_response :success
48 assert_select 'tr.time-entry' do
48 assert_select 'tr.time-entry' do
49 assert_select 'td.subject a[href=/issues/1]'
49 assert_select 'td.subject a[href=/issues/1]'
50 assert_select 'td.hours', :text => '2.50'
50 assert_select 'td.hours', :text => '2.50'
51 end
51 end
52 end
52 end
53
53
54 def test_page_with_all_blocks
54 def test_page_with_all_blocks
55 blocks = MyController::BLOCKS.keys
55 blocks = MyController::BLOCKS.keys
56 preferences = User.find(2).pref
56 preferences = User.find(2).pref
57 preferences[:my_page_layout] = {'top' => blocks}
57 preferences[:my_page_layout] = {'top' => blocks}
58 preferences.save!
58 preferences.save!
59
59
60 get :page
60 get :page
61 assert_response :success
61 assert_response :success
62 assert_select 'div.mypage-box', blocks.size
62 assert_select 'div.mypage-box', blocks.size
63 end
63 end
64
64
65 def test_my_account_should_show_editable_custom_fields
65 def test_my_account_should_show_editable_custom_fields
66 get :account
66 get :account
67 assert_response :success
67 assert_response :success
68 assert_template 'account'
68 assert_template 'account'
69 assert_equal User.find(2), assigns(:user)
69 assert_equal User.find(2), assigns(:user)
70
70
71 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
71 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
72 end
72 end
73
73
74 def test_my_account_should_not_show_non_editable_custom_fields
74 def test_my_account_should_not_show_non_editable_custom_fields
75 UserCustomField.find(4).update_attribute :editable, false
75 UserCustomField.find(4).update_attribute :editable, false
76
76
77 get :account
77 get :account
78 assert_response :success
78 assert_response :success
79 assert_template 'account'
79 assert_template 'account'
80 assert_equal User.find(2), assigns(:user)
80 assert_equal User.find(2), assigns(:user)
81
81
82 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
82 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
83 end
83 end
84
84
85 def test_update_account
85 def test_update_account
86 post :account,
86 post :account,
87 :user => {
87 :user => {
88 :firstname => "Joe",
88 :firstname => "Joe",
89 :login => "root",
89 :login => "root",
90 :admin => 1,
90 :admin => 1,
91 :group_ids => ['10'],
91 :group_ids => ['10'],
92 :custom_field_values => {"4" => "0100562500"}
92 :custom_field_values => {"4" => "0100562500"}
93 }
93 }
94
94
95 assert_redirected_to '/my/account'
95 assert_redirected_to '/my/account'
96 user = User.find(2)
96 user = User.find(2)
97 assert_equal user, assigns(:user)
97 assert_equal user, assigns(:user)
98 assert_equal "Joe", user.firstname
98 assert_equal "Joe", user.firstname
99 assert_equal "jsmith", user.login
99 assert_equal "jsmith", user.login
100 assert_equal "0100562500", user.custom_value_for(4).value
100 assert_equal "0100562500", user.custom_value_for(4).value
101 # ignored
101 # ignored
102 assert !user.admin?
102 assert !user.admin?
103 assert user.groups.empty?
103 assert user.groups.empty?
104 end
104 end
105
105
106 def test_my_account_should_show_destroy_link
106 def test_my_account_should_show_destroy_link
107 get :account
107 get :account
108 assert_select 'a[href=/my/account/destroy]'
108 assert_select 'a[href=/my/account/destroy]'
109 end
109 end
110
110
111 def test_get_destroy_should_display_the_destroy_confirmation
111 def test_get_destroy_should_display_the_destroy_confirmation
112 get :destroy
112 get :destroy
113 assert_response :success
113 assert_response :success
114 assert_template 'destroy'
114 assert_template 'destroy'
115 assert_select 'form[action=/my/account/destroy]' do
115 assert_select 'form[action=/my/account/destroy]' do
116 assert_select 'input[name=confirm]'
116 assert_select 'input[name=confirm]'
117 end
117 end
118 end
118 end
119
119
120 def test_post_destroy_without_confirmation_should_not_destroy_account
120 def test_post_destroy_without_confirmation_should_not_destroy_account
121 assert_no_difference 'User.count' do
121 assert_no_difference 'User.count' do
122 post :destroy
122 post :destroy
123 end
123 end
124 assert_response :success
124 assert_response :success
125 assert_template 'destroy'
125 assert_template 'destroy'
126 end
126 end
127
127
128 def test_post_destroy_without_confirmation_should_destroy_account
128 def test_post_destroy_without_confirmation_should_destroy_account
129 assert_difference 'User.count', -1 do
129 assert_difference 'User.count', -1 do
130 post :destroy, :confirm => '1'
130 post :destroy, :confirm => '1'
131 end
131 end
132 assert_redirected_to '/'
132 assert_redirected_to '/'
133 assert_match /deleted/i, flash[:notice]
133 assert_match /deleted/i, flash[:notice]
134 end
134 end
135
135
136 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
136 def test_post_destroy_with_unsubscribe_not_allowed_should_not_destroy_account
137 User.any_instance.stubs(:own_account_deletable?).returns(false)
137 User.any_instance.stubs(:own_account_deletable?).returns(false)
138
138
139 assert_no_difference 'User.count' do
139 assert_no_difference 'User.count' do
140 post :destroy, :confirm => '1'
140 post :destroy, :confirm => '1'
141 end
141 end
142 assert_redirected_to '/my/account'
142 assert_redirected_to '/my/account'
143 end
143 end
144
144
145 def test_change_password
145 def test_change_password
146 get :password
146 get :password
147 assert_response :success
147 assert_response :success
148 assert_template 'password'
148 assert_template 'password'
149
149
150 # non matching password confirmation
150 # non matching password confirmation
151 post :password, :password => 'jsmith',
151 post :password, :password => 'jsmith',
152 :new_password => 'secret123',
152 :new_password => 'secret123',
153 :new_password_confirmation => 'secret1234'
153 :new_password_confirmation => 'secret1234'
154 assert_response :success
154 assert_response :success
155 assert_template 'password'
155 assert_template 'password'
156 assert_error_tag :content => /Password doesn&#x27;t match confirmation/
156 assert_error_tag :content => /Password doesn&#x27;t match confirmation/
157
157
158 # wrong password
158 # wrong password
159 post :password, :password => 'wrongpassword',
159 post :password, :password => 'wrongpassword',
160 :new_password => 'secret123',
160 :new_password => 'secret123',
161 :new_password_confirmation => 'secret123'
161 :new_password_confirmation => 'secret123'
162 assert_response :success
162 assert_response :success
163 assert_template 'password'
163 assert_template 'password'
164 assert_equal 'Wrong password', flash[:error]
164 assert_equal 'Wrong password', flash[:error]
165
165
166 # good password
166 # good password
167 post :password, :password => 'jsmith',
167 post :password, :password => 'jsmith',
168 :new_password => 'secret123',
168 :new_password => 'secret123',
169 :new_password_confirmation => 'secret123'
169 :new_password_confirmation => 'secret123'
170 assert_redirected_to '/my/account'
170 assert_redirected_to '/my/account'
171 assert User.try_to_login('jsmith', 'secret123')
171 assert User.try_to_login('jsmith', 'secret123')
172 end
172 end
173
173
174 def test_change_password_should_redirect_if_user_cannot_change_its_password
174 def test_change_password_should_redirect_if_user_cannot_change_its_password
175 User.find(2).update_attribute(:auth_source_id, 1)
175 User.find(2).update_attribute(:auth_source_id, 1)
176
176
177 get :password
177 get :password
178 assert_not_nil flash[:error]
178 assert_not_nil flash[:error]
179 assert_redirected_to '/my/account'
179 assert_redirected_to '/my/account'
180 end
180 end
181
181
182 def test_page_layout
182 def test_page_layout
183 get :page_layout
183 get :page_layout
184 assert_response :success
184 assert_response :success
185 assert_template 'page_layout'
185 assert_template 'page_layout'
186 end
186 end
187
187
188 def test_add_block
188 def test_add_block
189 post :add_block, :block => 'issuesreportedbyme'
189 post :add_block, :block => 'issuesreportedbyme'
190 assert_redirected_to '/my/page_layout'
190 assert_redirected_to '/my/page_layout'
191 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
191 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
192 end
192 end
193
193
194 def test_add_invalid_block_should_redirect
195 post :add_block, :block => 'invalid'
196 assert_redirected_to '/my/page_layout'
197 end
198
194 def test_remove_block
199 def test_remove_block
195 post :remove_block, :block => 'issuesassignedtome'
200 post :remove_block, :block => 'issuesassignedtome'
196 assert_redirected_to '/my/page_layout'
201 assert_redirected_to '/my/page_layout'
197 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
202 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
198 end
203 end
199
204
200 def test_order_blocks
205 def test_order_blocks
201 xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews']
206 xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews']
202 assert_response :success
207 assert_response :success
203 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
208 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
204 end
209 end
205
210
206 def test_reset_rss_key_with_existing_key
211 def test_reset_rss_key_with_existing_key
207 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
212 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
208 post :reset_rss_key
213 post :reset_rss_key
209
214
210 assert_not_equal @previous_token_value, User.find(2).rss_key
215 assert_not_equal @previous_token_value, User.find(2).rss_key
211 assert User.find(2).rss_token
216 assert User.find(2).rss_token
212 assert_match /reset/, flash[:notice]
217 assert_match /reset/, flash[:notice]
213 assert_redirected_to '/my/account'
218 assert_redirected_to '/my/account'
214 end
219 end
215
220
216 def test_reset_rss_key_without_existing_key
221 def test_reset_rss_key_without_existing_key
217 assert_nil User.find(2).rss_token
222 assert_nil User.find(2).rss_token
218 post :reset_rss_key
223 post :reset_rss_key
219
224
220 assert User.find(2).rss_token
225 assert User.find(2).rss_token
221 assert_match /reset/, flash[:notice]
226 assert_match /reset/, flash[:notice]
222 assert_redirected_to '/my/account'
227 assert_redirected_to '/my/account'
223 end
228 end
224
229
225 def test_reset_api_key_with_existing_key
230 def test_reset_api_key_with_existing_key
226 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
231 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
227 post :reset_api_key
232 post :reset_api_key
228
233
229 assert_not_equal @previous_token_value, User.find(2).api_key
234 assert_not_equal @previous_token_value, User.find(2).api_key
230 assert User.find(2).api_token
235 assert User.find(2).api_token
231 assert_match /reset/, flash[:notice]
236 assert_match /reset/, flash[:notice]
232 assert_redirected_to '/my/account'
237 assert_redirected_to '/my/account'
233 end
238 end
234
239
235 def test_reset_api_key_without_existing_key
240 def test_reset_api_key_without_existing_key
236 assert_nil User.find(2).api_token
241 assert_nil User.find(2).api_token
237 post :reset_api_key
242 post :reset_api_key
238
243
239 assert User.find(2).api_token
244 assert User.find(2).api_token
240 assert_match /reset/, flash[:notice]
245 assert_match /reset/, flash[:notice]
241 assert_redirected_to '/my/account'
246 assert_redirected_to '/my/account'
242 end
247 end
243 end
248 end
General Comments 0
You need to be logged in to leave comments. Login now