@@ -1,207 +1,207 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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 | require 'my_controller' |
|
19 | require 'my_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class MyController; def rescue_action(e) raise e end; end |
|
22 | class MyController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class MyControllerTest < ActionController::TestCase |
|
24 | class MyControllerTest < ActionController::TestCase | |
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields |
|
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = MyController.new |
|
28 | @controller = MyController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @request.session[:user_id] = 2 |
|
30 | @request.session[:user_id] = 2 | |
31 | @response = ActionController::TestResponse.new |
|
31 | @response = ActionController::TestResponse.new | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_index |
|
34 | def test_index | |
35 | get :index |
|
35 | get :index | |
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 |
|
40 | def test_page | |
41 | get :page |
|
41 | get :page | |
42 | assert_response :success |
|
42 | assert_response :success | |
43 | assert_template 'page' |
|
43 | assert_template 'page' | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_my_account_should_show_editable_custom_fields |
|
46 | def test_my_account_should_show_editable_custom_fields | |
47 | get :account |
|
47 | get :account | |
48 | assert_response :success |
|
48 | assert_response :success | |
49 | assert_template 'account' |
|
49 | assert_template 'account' | |
50 | assert_equal User.find(2), assigns(:user) |
|
50 | assert_equal User.find(2), assigns(:user) | |
51 |
|
51 | |||
52 | assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
52 | assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_my_account_should_not_show_non_editable_custom_fields |
|
55 | def test_my_account_should_not_show_non_editable_custom_fields | |
56 | UserCustomField.find(4).update_attribute :editable, false |
|
56 | UserCustomField.find(4).update_attribute :editable, false | |
57 |
|
57 | |||
58 | get :account |
|
58 | get :account | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'account' |
|
60 | assert_template 'account' | |
61 | assert_equal User.find(2), assigns(:user) |
|
61 | assert_equal User.find(2), assigns(:user) | |
62 |
|
62 | |||
63 | assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} |
|
63 | assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'} | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_update_account |
|
66 | def test_update_account | |
67 | post :account, |
|
67 | post :account, | |
68 | :user => { |
|
68 | :user => { | |
69 | :firstname => "Joe", |
|
69 | :firstname => "Joe", | |
70 | :login => "root", |
|
70 | :login => "root", | |
71 | :admin => 1, |
|
71 | :admin => 1, | |
72 | :group_ids => ['10'], |
|
72 | :group_ids => ['10'], | |
73 | :custom_field_values => {"4" => "0100562500"} |
|
73 | :custom_field_values => {"4" => "0100562500"} | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | assert_redirected_to '/my/account' |
|
76 | assert_redirected_to '/my/account' | |
77 | user = User.find(2) |
|
77 | user = User.find(2) | |
78 | assert_equal user, assigns(:user) |
|
78 | assert_equal user, assigns(:user) | |
79 | assert_equal "Joe", user.firstname |
|
79 | assert_equal "Joe", user.firstname | |
80 | assert_equal "jsmith", user.login |
|
80 | assert_equal "jsmith", user.login | |
81 | assert_equal "0100562500", user.custom_value_for(4).value |
|
81 | assert_equal "0100562500", user.custom_value_for(4).value | |
82 | # ignored |
|
82 | # ignored | |
83 | assert !user.admin? |
|
83 | assert !user.admin? | |
84 | assert user.groups.empty? |
|
84 | assert user.groups.empty? | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_change_password |
|
87 | def test_change_password | |
88 | get :password |
|
88 | get :password | |
89 | assert_response :success |
|
89 | assert_response :success | |
90 | assert_template 'password' |
|
90 | assert_template 'password' | |
91 |
|
91 | |||
92 | # non matching password confirmation |
|
92 | # non matching password confirmation | |
93 |
post :password, :password => 'jsmith', |
|
93 | post :password, :password => 'jsmith', | |
94 | :new_password => 'hello', |
|
94 | :new_password => 'hello', | |
95 | :new_password_confirmation => 'hello2' |
|
95 | :new_password_confirmation => 'hello2' | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'password' |
|
97 | assert_template 'password' | |
98 | assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } |
|
98 | assert_tag :tag => "div", :attributes => { :class => "errorExplanation" } | |
99 |
|
99 | |||
100 | # wrong password |
|
100 | # wrong password | |
101 |
post :password, :password => 'wrongpassword', |
|
101 | post :password, :password => 'wrongpassword', | |
102 | :new_password => 'hello', |
|
102 | :new_password => 'hello', | |
103 | :new_password_confirmation => 'hello' |
|
103 | :new_password_confirmation => 'hello' | |
104 | assert_response :success |
|
104 | assert_response :success | |
105 | assert_template 'password' |
|
105 | assert_template 'password' | |
106 | assert_equal 'Wrong password', flash[:error] |
|
106 | assert_equal 'Wrong password', flash[:error] | |
107 |
|
107 | |||
108 | # good password |
|
108 | # good password | |
109 | post :password, :password => 'jsmith', |
|
109 | post :password, :password => 'jsmith', | |
110 | :new_password => 'hello', |
|
110 | :new_password => 'hello', | |
111 | :new_password_confirmation => 'hello' |
|
111 | :new_password_confirmation => 'hello' | |
112 | assert_redirected_to '/my/account' |
|
112 | assert_redirected_to '/my/account' | |
113 | assert User.try_to_login('jsmith', 'hello') |
|
113 | assert User.try_to_login('jsmith', 'hello') | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def test_page_layout |
|
116 | def test_page_layout | |
117 | get :page_layout |
|
117 | get :page_layout | |
118 | assert_response :success |
|
118 | assert_response :success | |
119 | assert_template 'page_layout' |
|
119 | assert_template 'page_layout' | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_add_block |
|
122 | def test_add_block | |
123 | xhr :post, :add_block, :block => 'issuesreportedbyme' |
|
123 | xhr :post, :add_block, :block => 'issuesreportedbyme' | |
124 | assert_response :success |
|
124 | assert_response :success | |
125 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') |
|
125 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_remove_block |
|
128 | def test_remove_block | |
129 | xhr :post, :remove_block, :block => 'issuesassignedtome' |
|
129 | xhr :post, :remove_block, :block => 'issuesassignedtome' | |
130 | assert_response :success |
|
130 | assert_response :success | |
131 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') |
|
131 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_order_blocks |
|
134 | def test_order_blocks | |
135 | xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] |
|
135 | xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] | |
136 | assert_response :success |
|
136 | assert_response :success | |
137 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] |
|
137 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | context "POST to reset_rss_key" do |
|
140 | context "POST to reset_rss_key" do | |
141 | context "with an existing rss_token" do |
|
141 | context "with an existing rss_token" do | |
142 | setup do |
|
142 | setup do | |
143 | @previous_token_value = User.find(2).rss_key # Will generate one if it's missing |
|
143 | @previous_token_value = User.find(2).rss_key # Will generate one if it's missing | |
144 | post :reset_rss_key |
|
144 | post :reset_rss_key | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | should "destroy the existing token" do |
|
147 | should "destroy the existing token" do | |
148 | assert_not_equal @previous_token_value, User.find(2).rss_key |
|
148 | assert_not_equal @previous_token_value, User.find(2).rss_key | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | should "create a new token" do |
|
151 | should "create a new token" do | |
152 | assert User.find(2).rss_token |
|
152 | assert User.find(2).rss_token | |
153 | end |
|
153 | end | |
154 |
|
154 | |||
155 | should_set_the_flash_to /reset/ |
|
155 | should_set_the_flash_to /reset/ | |
156 | should_redirect_to('my account') {'/my/account' } |
|
156 | should_redirect_to('my account') {'/my/account' } | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | context "with no rss_token" do |
|
159 | context "with no rss_token" do | |
160 | setup do |
|
160 | setup do | |
161 | assert_nil User.find(2).rss_token |
|
161 | assert_nil User.find(2).rss_token | |
162 | post :reset_rss_key |
|
162 | post :reset_rss_key | |
163 | end |
|
163 | end | |
164 |
|
164 | |||
165 | should "create a new token" do |
|
165 | should "create a new token" do | |
166 | assert User.find(2).rss_token |
|
166 | assert User.find(2).rss_token | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | should_set_the_flash_to /reset/ |
|
169 | should_set_the_flash_to /reset/ | |
170 | should_redirect_to('my account') {'/my/account' } |
|
170 | should_redirect_to('my account') {'/my/account' } | |
171 | end |
|
171 | end | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | context "POST to reset_api_key" do |
|
174 | context "POST to reset_api_key" do | |
175 | context "with an existing api_token" do |
|
175 | context "with an existing api_token" do | |
176 | setup do |
|
176 | setup do | |
177 | @previous_token_value = User.find(2).api_key # Will generate one if it's missing |
|
177 | @previous_token_value = User.find(2).api_key # Will generate one if it's missing | |
178 | post :reset_api_key |
|
178 | post :reset_api_key | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | should "destroy the existing token" do |
|
181 | should "destroy the existing token" do | |
182 | assert_not_equal @previous_token_value, User.find(2).api_key |
|
182 | assert_not_equal @previous_token_value, User.find(2).api_key | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | should "create a new token" do |
|
185 | should "create a new token" do | |
186 | assert User.find(2).api_token |
|
186 | assert User.find(2).api_token | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | should_set_the_flash_to /reset/ |
|
189 | should_set_the_flash_to /reset/ | |
190 | should_redirect_to('my account') {'/my/account' } |
|
190 | should_redirect_to('my account') {'/my/account' } | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | context "with no api_token" do |
|
193 | context "with no api_token" do | |
194 | setup do |
|
194 | setup do | |
195 | assert_nil User.find(2).api_token |
|
195 | assert_nil User.find(2).api_token | |
196 | post :reset_api_key |
|
196 | post :reset_api_key | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | should "create a new token" do |
|
199 | should "create a new token" do | |
200 | assert User.find(2).api_token |
|
200 | assert User.find(2).api_token | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | should_set_the_flash_to /reset/ |
|
203 | should_set_the_flash_to /reset/ | |
204 | should_redirect_to('my account') {'/my/account' } |
|
204 | should_redirect_to('my account') {'/my/account' } | |
205 | end |
|
205 | end | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end |
General Comments 0
You need to be logged in to leave comments.
Login now