##// END OF EJS Templates
Adds leading slash to all assert_redirected_to arguments (#6887)....
Jean-Philippe Lang -
r4293:2fab7bd9b1f1
parent child
Show More
@@ -1,224 +1,224
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'account_controller'
19 require 'account_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AccountController; def rescue_action(e) raise e end; end
22 class AccountController; def rescue_action(e) raise e end; end
23
23
24 class AccountControllerTest < ActionController::TestCase
24 class AccountControllerTest < ActionController::TestCase
25 fixtures :users, :roles
25 fixtures :users, :roles
26
26
27 def setup
27 def setup
28 @controller = AccountController.new
28 @controller = AccountController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_login_should_redirect_to_back_url_param
34 def test_login_should_redirect_to_back_url_param
35 # request.uri is "test.host" in test environment
35 # request.uri is "test.host" in test environment
36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
36 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
37 assert_redirected_to '/issues/show/1'
37 assert_redirected_to '/issues/show/1'
38 end
38 end
39
39
40 def test_login_should_not_redirect_to_another_host
40 def test_login_should_not_redirect_to_another_host
41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
41 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
42 assert_redirected_to '/my/page'
42 assert_redirected_to '/my/page'
43 end
43 end
44
44
45 def test_login_with_wrong_password
45 def test_login_with_wrong_password
46 post :login, :username => 'admin', :password => 'bad'
46 post :login, :username => 'admin', :password => 'bad'
47 assert_response :success
47 assert_response :success
48 assert_template 'login'
48 assert_template 'login'
49 assert_tag 'div',
49 assert_tag 'div',
50 :attributes => { :class => "flash error" },
50 :attributes => { :class => "flash error" },
51 :content => /Invalid user or password/
51 :content => /Invalid user or password/
52 end
52 end
53
53
54 if Object.const_defined?(:OpenID)
54 if Object.const_defined?(:OpenID)
55
55
56 def test_login_with_openid_for_existing_user
56 def test_login_with_openid_for_existing_user
57 Setting.self_registration = '3'
57 Setting.self_registration = '3'
58 Setting.openid = '1'
58 Setting.openid = '1'
59 existing_user = User.new(:firstname => 'Cool',
59 existing_user = User.new(:firstname => 'Cool',
60 :lastname => 'User',
60 :lastname => 'User',
61 :mail => 'user@somedomain.com',
61 :mail => 'user@somedomain.com',
62 :identity_url => 'http://openid.example.com/good_user')
62 :identity_url => 'http://openid.example.com/good_user')
63 existing_user.login = 'cool_user'
63 existing_user.login = 'cool_user'
64 assert existing_user.save!
64 assert existing_user.save!
65
65
66 post :login, :openid_url => existing_user.identity_url
66 post :login, :openid_url => existing_user.identity_url
67 assert_redirected_to 'my/page'
67 assert_redirected_to '/my/page'
68 end
68 end
69
69
70 def test_login_with_invalid_openid_provider
70 def test_login_with_invalid_openid_provider
71 Setting.self_registration = '0'
71 Setting.self_registration = '0'
72 Setting.openid = '1'
72 Setting.openid = '1'
73 post :login, :openid_url => 'http;//openid.example.com/good_user'
73 post :login, :openid_url => 'http;//openid.example.com/good_user'
74 assert_redirected_to home_url
74 assert_redirected_to home_url
75 end
75 end
76
76
77 def test_login_with_openid_for_existing_non_active_user
77 def test_login_with_openid_for_existing_non_active_user
78 Setting.self_registration = '2'
78 Setting.self_registration = '2'
79 Setting.openid = '1'
79 Setting.openid = '1'
80 existing_user = User.new(:firstname => 'Cool',
80 existing_user = User.new(:firstname => 'Cool',
81 :lastname => 'User',
81 :lastname => 'User',
82 :mail => 'user@somedomain.com',
82 :mail => 'user@somedomain.com',
83 :identity_url => 'http://openid.example.com/good_user',
83 :identity_url => 'http://openid.example.com/good_user',
84 :status => User::STATUS_REGISTERED)
84 :status => User::STATUS_REGISTERED)
85 existing_user.login = 'cool_user'
85 existing_user.login = 'cool_user'
86 assert existing_user.save!
86 assert existing_user.save!
87
87
88 post :login, :openid_url => existing_user.identity_url
88 post :login, :openid_url => existing_user.identity_url
89 assert_redirected_to 'login'
89 assert_redirected_to '/login'
90 end
90 end
91
91
92 def test_login_with_openid_with_new_user_created
92 def test_login_with_openid_with_new_user_created
93 Setting.self_registration = '3'
93 Setting.self_registration = '3'
94 Setting.openid = '1'
94 Setting.openid = '1'
95 post :login, :openid_url => 'http://openid.example.com/good_user'
95 post :login, :openid_url => 'http://openid.example.com/good_user'
96 assert_redirected_to 'my/account'
96 assert_redirected_to '/my/account'
97 user = User.find_by_login('cool_user')
97 user = User.find_by_login('cool_user')
98 assert user
98 assert user
99 assert_equal 'Cool', user.firstname
99 assert_equal 'Cool', user.firstname
100 assert_equal 'User', user.lastname
100 assert_equal 'User', user.lastname
101 end
101 end
102
102
103 def test_login_with_openid_with_new_user_and_self_registration_off
103 def test_login_with_openid_with_new_user_and_self_registration_off
104 Setting.self_registration = '0'
104 Setting.self_registration = '0'
105 Setting.openid = '1'
105 Setting.openid = '1'
106 post :login, :openid_url => 'http://openid.example.com/good_user'
106 post :login, :openid_url => 'http://openid.example.com/good_user'
107 assert_redirected_to home_url
107 assert_redirected_to home_url
108 user = User.find_by_login('cool_user')
108 user = User.find_by_login('cool_user')
109 assert ! user
109 assert ! user
110 end
110 end
111
111
112 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
112 def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
113 Setting.self_registration = '1'
113 Setting.self_registration = '1'
114 Setting.openid = '1'
114 Setting.openid = '1'
115 post :login, :openid_url => 'http://openid.example.com/good_user'
115 post :login, :openid_url => 'http://openid.example.com/good_user'
116 assert_redirected_to 'login'
116 assert_redirected_to '/login'
117 user = User.find_by_login('cool_user')
117 user = User.find_by_login('cool_user')
118 assert user
118 assert user
119
119
120 token = Token.find_by_user_id_and_action(user.id, 'register')
120 token = Token.find_by_user_id_and_action(user.id, 'register')
121 assert token
121 assert token
122 end
122 end
123
123
124 def test_login_with_openid_with_new_user_created_with_manual_activation
124 def test_login_with_openid_with_new_user_created_with_manual_activation
125 Setting.self_registration = '2'
125 Setting.self_registration = '2'
126 Setting.openid = '1'
126 Setting.openid = '1'
127 post :login, :openid_url => 'http://openid.example.com/good_user'
127 post :login, :openid_url => 'http://openid.example.com/good_user'
128 assert_redirected_to 'login'
128 assert_redirected_to '/login'
129 user = User.find_by_login('cool_user')
129 user = User.find_by_login('cool_user')
130 assert user
130 assert user
131 assert_equal User::STATUS_REGISTERED, user.status
131 assert_equal User::STATUS_REGISTERED, user.status
132 end
132 end
133
133
134 def test_login_with_openid_with_new_user_with_conflict_should_register
134 def test_login_with_openid_with_new_user_with_conflict_should_register
135 Setting.self_registration = '3'
135 Setting.self_registration = '3'
136 Setting.openid = '1'
136 Setting.openid = '1'
137 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
137 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
138 existing_user.login = 'cool_user'
138 existing_user.login = 'cool_user'
139 assert existing_user.save!
139 assert existing_user.save!
140
140
141 post :login, :openid_url => 'http://openid.example.com/good_user'
141 post :login, :openid_url => 'http://openid.example.com/good_user'
142 assert_response :success
142 assert_response :success
143 assert_template 'register'
143 assert_template 'register'
144 assert assigns(:user)
144 assert assigns(:user)
145 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
145 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
146 end
146 end
147
147
148 def test_setting_openid_should_return_true_when_set_to_true
148 def test_setting_openid_should_return_true_when_set_to_true
149 Setting.openid = '1'
149 Setting.openid = '1'
150 assert_equal true, Setting.openid?
150 assert_equal true, Setting.openid?
151 end
151 end
152
152
153 else
153 else
154 puts "Skipping openid tests."
154 puts "Skipping openid tests."
155 end
155 end
156
156
157 def test_logout
157 def test_logout
158 @request.session[:user_id] = 2
158 @request.session[:user_id] = 2
159 get :logout
159 get :logout
160 assert_redirected_to ''
160 assert_redirected_to '/'
161 assert_nil @request.session[:user_id]
161 assert_nil @request.session[:user_id]
162 end
162 end
163
163
164 context "GET #register" do
164 context "GET #register" do
165 context "with self registration on" do
165 context "with self registration on" do
166 setup do
166 setup do
167 Setting.self_registration = '3'
167 Setting.self_registration = '3'
168 get :register
168 get :register
169 end
169 end
170
170
171 should_respond_with :success
171 should_respond_with :success
172 should_render_template :register
172 should_render_template :register
173 should_assign_to :user
173 should_assign_to :user
174 end
174 end
175
175
176 context "with self registration off" do
176 context "with self registration off" do
177 setup do
177 setup do
178 Setting.self_registration = '0'
178 Setting.self_registration = '0'
179 get :register
179 get :register
180 end
180 end
181
181
182 should_redirect_to('/') { home_url }
182 should_redirect_to('/') { home_url }
183 end
183 end
184 end
184 end
185
185
186 # See integration/account_test.rb for the full test
186 # See integration/account_test.rb for the full test
187 context "POST #register" do
187 context "POST #register" do
188 context "with self registration on automatic" do
188 context "with self registration on automatic" do
189 setup do
189 setup do
190 Setting.self_registration = '3'
190 Setting.self_registration = '3'
191 post :register, :user => {
191 post :register, :user => {
192 :login => 'register',
192 :login => 'register',
193 :password => 'test',
193 :password => 'test',
194 :password_confirmation => 'test',
194 :password_confirmation => 'test',
195 :firstname => 'John',
195 :firstname => 'John',
196 :lastname => 'Doe',
196 :lastname => 'Doe',
197 :mail => 'register@example.com'
197 :mail => 'register@example.com'
198 }
198 }
199 end
199 end
200
200
201 should_respond_with :redirect
201 should_respond_with :redirect
202 should_assign_to :user
202 should_assign_to :user
203 should_redirect_to('my page') { {:controller => 'my', :action => 'account'} }
203 should_redirect_to('my page') { {:controller => 'my', :action => 'account'} }
204
204
205 should_create_a_new_user { User.last(:conditions => {:login => 'register'}) }
205 should_create_a_new_user { User.last(:conditions => {:login => 'register'}) }
206
206
207 should 'set the user status to active' do
207 should 'set the user status to active' do
208 user = User.last(:conditions => {:login => 'register'})
208 user = User.last(:conditions => {:login => 'register'})
209 assert user
209 assert user
210 assert_equal User::STATUS_ACTIVE, user.status
210 assert_equal User::STATUS_ACTIVE, user.status
211 end
211 end
212 end
212 end
213
213
214 context "with self registration off" do
214 context "with self registration off" do
215 setup do
215 setup do
216 Setting.self_registration = '0'
216 Setting.self_registration = '0'
217 post :register
217 post :register
218 end
218 end
219
219
220 should_redirect_to('/') { home_url }
220 should_redirect_to('/') { home_url }
221 end
221 end
222 end
222 end
223
223
224 end
224 end
@@ -1,135 +1,135
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'attachments_controller'
19 require 'attachments_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class AttachmentsController; def rescue_action(e) raise e end; end
22 class AttachmentsController; def rescue_action(e) raise e end; end
23
23
24
24
25 class AttachmentsControllerTest < ActionController::TestCase
25 class AttachmentsControllerTest < ActionController::TestCase
26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
27 :versions, :wiki_pages, :wikis, :documents
27 :versions, :wiki_pages, :wikis, :documents
28
28
29 def setup
29 def setup
30 @controller = AttachmentsController.new
30 @controller = AttachmentsController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
34 User.current = nil
34 User.current = nil
35 end
35 end
36
36
37 def test_show_diff
37 def test_show_diff
38 get :show, :id => 5
38 get :show, :id => 5
39 assert_response :success
39 assert_response :success
40 assert_template 'diff'
40 assert_template 'diff'
41 assert_equal 'text/html', @response.content_type
41 assert_equal 'text/html', @response.content_type
42 end
42 end
43
43
44 def test_show_text_file
44 def test_show_text_file
45 get :show, :id => 4
45 get :show, :id => 4
46 assert_response :success
46 assert_response :success
47 assert_template 'file'
47 assert_template 'file'
48 assert_equal 'text/html', @response.content_type
48 assert_equal 'text/html', @response.content_type
49 end
49 end
50
50
51 def test_show_text_file_should_send_if_too_big
51 def test_show_text_file_should_send_if_too_big
52 Setting.file_max_size_displayed = 512
52 Setting.file_max_size_displayed = 512
53 Attachment.find(4).update_attribute :filesize, 754.kilobyte
53 Attachment.find(4).update_attribute :filesize, 754.kilobyte
54
54
55 get :show, :id => 4
55 get :show, :id => 4
56 assert_response :success
56 assert_response :success
57 assert_equal 'application/x-ruby', @response.content_type
57 assert_equal 'application/x-ruby', @response.content_type
58 end
58 end
59
59
60 def test_show_other
60 def test_show_other
61 get :show, :id => 6
61 get :show, :id => 6
62 assert_response :success
62 assert_response :success
63 assert_equal 'application/octet-stream', @response.content_type
63 assert_equal 'application/octet-stream', @response.content_type
64 end
64 end
65
65
66 def test_download_text_file
66 def test_download_text_file
67 get :download, :id => 4
67 get :download, :id => 4
68 assert_response :success
68 assert_response :success
69 assert_equal 'application/x-ruby', @response.content_type
69 assert_equal 'application/x-ruby', @response.content_type
70 end
70 end
71
71
72 def test_download_should_assign_content_type_if_blank
72 def test_download_should_assign_content_type_if_blank
73 Attachment.find(4).update_attribute(:content_type, '')
73 Attachment.find(4).update_attribute(:content_type, '')
74
74
75 get :download, :id => 4
75 get :download, :id => 4
76 assert_response :success
76 assert_response :success
77 assert_equal 'text/x-ruby', @response.content_type
77 assert_equal 'text/x-ruby', @response.content_type
78 end
78 end
79
79
80 def test_download_missing_file
80 def test_download_missing_file
81 get :download, :id => 2
81 get :download, :id => 2
82 assert_response 404
82 assert_response 404
83 end
83 end
84
84
85 def test_anonymous_on_private_private
85 def test_anonymous_on_private_private
86 get :download, :id => 7
86 get :download, :id => 7
87 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
87 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
88 end
88 end
89
89
90 def test_destroy_issue_attachment
90 def test_destroy_issue_attachment
91 issue = Issue.find(3)
91 issue = Issue.find(3)
92 @request.session[:user_id] = 2
92 @request.session[:user_id] = 2
93
93
94 assert_difference 'issue.attachments.count', -1 do
94 assert_difference 'issue.attachments.count', -1 do
95 post :destroy, :id => 1
95 post :destroy, :id => 1
96 end
96 end
97 # no referrer
97 # no referrer
98 assert_redirected_to 'projects/ecookbook'
98 assert_redirected_to '/projects/ecookbook'
99 assert_nil Attachment.find_by_id(1)
99 assert_nil Attachment.find_by_id(1)
100 j = issue.journals.find(:first, :order => 'created_on DESC')
100 j = issue.journals.find(:first, :order => 'created_on DESC')
101 assert_equal 'attachment', j.details.first.property
101 assert_equal 'attachment', j.details.first.property
102 assert_equal '1', j.details.first.prop_key
102 assert_equal '1', j.details.first.prop_key
103 assert_equal 'error281.txt', j.details.first.old_value
103 assert_equal 'error281.txt', j.details.first.old_value
104 end
104 end
105
105
106 def test_destroy_wiki_page_attachment
106 def test_destroy_wiki_page_attachment
107 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
108 assert_difference 'Attachment.count', -1 do
108 assert_difference 'Attachment.count', -1 do
109 post :destroy, :id => 3
109 post :destroy, :id => 3
110 assert_response 302
110 assert_response 302
111 end
111 end
112 end
112 end
113
113
114 def test_destroy_project_attachment
114 def test_destroy_project_attachment
115 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
116 assert_difference 'Attachment.count', -1 do
116 assert_difference 'Attachment.count', -1 do
117 post :destroy, :id => 8
117 post :destroy, :id => 8
118 assert_response 302
118 assert_response 302
119 end
119 end
120 end
120 end
121
121
122 def test_destroy_version_attachment
122 def test_destroy_version_attachment
123 @request.session[:user_id] = 2
123 @request.session[:user_id] = 2
124 assert_difference 'Attachment.count', -1 do
124 assert_difference 'Attachment.count', -1 do
125 post :destroy, :id => 9
125 post :destroy, :id => 9
126 assert_response 302
126 assert_response 302
127 end
127 end
128 end
128 end
129
129
130 def test_destroy_without_permission
130 def test_destroy_without_permission
131 post :destroy, :id => 3
131 post :destroy, :id => 3
132 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
132 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
133 assert Attachment.find_by_id(3)
133 assert Attachment.find_by_id(3)
134 end
134 end
135 end
135 end
@@ -1,57 +1,57
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class CommentsControllerTest < ActionController::TestCase
20 class CommentsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 end
25 end
26
26
27 def test_add_comment
27 def test_add_comment
28 @request.session[:user_id] = 2
28 @request.session[:user_id] = 2
29 post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
29 post :create, :id => 1, :comment => { :comments => 'This is a test comment' }
30 assert_redirected_to 'news/1'
30 assert_redirected_to '/news/1'
31
31
32 comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
32 comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
33 assert_not_nil comment
33 assert_not_nil comment
34 assert_equal 'This is a test comment', comment.comments
34 assert_equal 'This is a test comment', comment.comments
35 assert_equal User.find(2), comment.author
35 assert_equal User.find(2), comment.author
36 end
36 end
37
37
38 def test_empty_comment_should_not_be_added
38 def test_empty_comment_should_not_be_added
39 @request.session[:user_id] = 2
39 @request.session[:user_id] = 2
40 assert_no_difference 'Comment.count' do
40 assert_no_difference 'Comment.count' do
41 post :create, :id => 1, :comment => { :comments => '' }
41 post :create, :id => 1, :comment => { :comments => '' }
42 assert_response :redirect
42 assert_response :redirect
43 assert_redirected_to 'news/1'
43 assert_redirected_to '/news/1'
44 end
44 end
45 end
45 end
46
46
47 def test_destroy_comment
47 def test_destroy_comment
48 comments_count = News.find(1).comments.size
48 comments_count = News.find(1).comments.size
49 @request.session[:user_id] = 2
49 @request.session[:user_id] = 2
50 delete :destroy, :id => 1, :comment_id => 2
50 delete :destroy, :id => 1, :comment_id => 2
51 assert_redirected_to 'news/1'
51 assert_redirected_to '/news/1'
52 assert_nil Comment.find_by_id(2)
52 assert_nil Comment.find_by_id(2)
53 assert_equal comments_count - 1, News.find(1).comments.size
53 assert_equal comments_count - 1, News.find(1).comments.size
54 end
54 end
55
55
56
56
57 end
57 end
@@ -1,96 +1,96
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'documents_controller'
19 require 'documents_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class DocumentsController; def rescue_action(e) raise e end; end
22 class DocumentsController; def rescue_action(e) raise e end; end
23
23
24 class DocumentsControllerTest < ActionController::TestCase
24 class DocumentsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
26
26
27 def setup
27 def setup
28 @controller = DocumentsController.new
28 @controller = DocumentsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_index
34 def test_index
35 # Sets a default category
35 # Sets a default category
36 e = Enumeration.find_by_name('Technical documentation')
36 e = Enumeration.find_by_name('Technical documentation')
37 e.update_attributes(:is_default => true)
37 e.update_attributes(:is_default => true)
38
38
39 get :index, :project_id => 'ecookbook'
39 get :index, :project_id => 'ecookbook'
40 assert_response :success
40 assert_response :success
41 assert_template 'index'
41 assert_template 'index'
42 assert_not_nil assigns(:grouped)
42 assert_not_nil assigns(:grouped)
43
43
44 # Default category selected in the new document form
44 # Default category selected in the new document form
45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
47 :content => 'Technical documentation'}
47 :content => 'Technical documentation'}
48 end
48 end
49
49
50 def test_index_with_long_description
50 def test_index_with_long_description
51 # adds a long description to the first document
51 # adds a long description to the first document
52 doc = documents(:documents_001)
52 doc = documents(:documents_001)
53 doc.update_attributes(:description => <<LOREM)
53 doc.update_attributes(:description => <<LOREM)
54 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra. Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
54 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci, eget tristique ante sem vel mi. Nulla facilisi. Donec enim libero, luctus ac sagittis sit amet, vehicula sagittis magna. Duis ultrices molestie ante, eget scelerisque sem iaculis vitae. Etiam fermentum mauris vitae metus pharetra condimentum fermentum est pretium. Proin sollicitudin elementum quam quis pharetra. Aenean facilisis nunc quis elit volutpat mollis. Aenean eleifend varius euismod. Ut dolor est, congue eget dapibus eget, elementum eu odio. Integer et lectus neque, nec scelerisque nisi. EndOfLineHere
55
55
56 Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
56 Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus. Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
57 LOREM
57 LOREM
58
58
59 get :index, :project_id => 'ecookbook'
59 get :index, :project_id => 'ecookbook'
60 assert_response :success
60 assert_response :success
61 assert_template 'index'
61 assert_template 'index'
62
62
63 # should only truncate on new lines to avoid breaking wiki formatting
63 # should only truncate on new lines to avoid breaking wiki formatting
64 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
64 assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
65 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
65 assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
66 end
66 end
67
67
68 def test_new_with_one_attachment
68 def test_new_with_one_attachment
69 ActionMailer::Base.deliveries.clear
69 ActionMailer::Base.deliveries.clear
70 Setting.notified_events << 'document_added'
70 Setting.notified_events << 'document_added'
71 @request.session[:user_id] = 2
71 @request.session[:user_id] = 2
72 set_tmp_attachments_directory
72 set_tmp_attachments_directory
73
73
74 post :new, :project_id => 'ecookbook',
74 post :new, :project_id => 'ecookbook',
75 :document => { :title => 'DocumentsControllerTest#test_post_new',
75 :document => { :title => 'DocumentsControllerTest#test_post_new',
76 :description => 'This is a new document',
76 :description => 'This is a new document',
77 :category_id => 2},
77 :category_id => 2},
78 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
78 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
79
79
80 assert_redirected_to 'projects/ecookbook/documents'
80 assert_redirected_to '/projects/ecookbook/documents'
81
81
82 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
82 document = Document.find_by_title('DocumentsControllerTest#test_post_new')
83 assert_not_nil document
83 assert_not_nil document
84 assert_equal Enumeration.find(2), document.category
84 assert_equal Enumeration.find(2), document.category
85 assert_equal 1, document.attachments.size
85 assert_equal 1, document.attachments.size
86 assert_equal 'testfile.txt', document.attachments.first.filename
86 assert_equal 'testfile.txt', document.attachments.first.filename
87 assert_equal 1, ActionMailer::Base.deliveries.size
87 assert_equal 1, ActionMailer::Base.deliveries.size
88 end
88 end
89
89
90 def test_destroy
90 def test_destroy
91 @request.session[:user_id] = 2
91 @request.session[:user_id] = 2
92 post :destroy, :id => 1
92 post :destroy, :id => 1
93 assert_redirected_to 'projects/ecookbook/documents'
93 assert_redirected_to '/projects/ecookbook/documents'
94 assert_nil Document.find_by_id(1)
94 assert_nil Document.find_by_id(1)
95 end
95 end
96 end
96 end
@@ -1,67 +1,67
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2
2
3 class FilesControllerTest < ActionController::TestCase
3 class FilesControllerTest < ActionController::TestCase
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 @controller = FilesController.new
7 @controller = FilesController.new
8 @request = ActionController::TestRequest.new
8 @request = ActionController::TestRequest.new
9 @response = ActionController::TestResponse.new
9 @response = ActionController::TestResponse.new
10 @request.session[:user_id] = nil
10 @request.session[:user_id] = nil
11 Setting.default_language = 'en'
11 Setting.default_language = 'en'
12 end
12 end
13
13
14 def test_index
14 def test_index
15 get :index, :project_id => 1
15 get :index, :project_id => 1
16 assert_response :success
16 assert_response :success
17 assert_template 'index'
17 assert_template 'index'
18 assert_not_nil assigns(:containers)
18 assert_not_nil assigns(:containers)
19
19
20 # file attached to the project
20 # file attached to the project
21 assert_tag :a, :content => 'project_file.zip',
21 assert_tag :a, :content => 'project_file.zip',
22 :attributes => { :href => '/attachments/download/8/project_file.zip' }
22 :attributes => { :href => '/attachments/download/8/project_file.zip' }
23
23
24 # file attached to a project's version
24 # file attached to a project's version
25 assert_tag :a, :content => 'version_file.zip',
25 assert_tag :a, :content => 'version_file.zip',
26 :attributes => { :href => '/attachments/download/9/version_file.zip' }
26 :attributes => { :href => '/attachments/download/9/version_file.zip' }
27 end
27 end
28
28
29 def test_create_file
29 def test_create_file
30 set_tmp_attachments_directory
30 set_tmp_attachments_directory
31 @request.session[:user_id] = 2
31 @request.session[:user_id] = 2
32 Setting.notified_events = ['file_added']
32 Setting.notified_events = ['file_added']
33 ActionMailer::Base.deliveries.clear
33 ActionMailer::Base.deliveries.clear
34
34
35 assert_difference 'Attachment.count' do
35 assert_difference 'Attachment.count' do
36 post :create, :project_id => 1, :version_id => '',
36 post :create, :project_id => 1, :version_id => '',
37 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
37 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
38 assert_response :redirect
38 assert_response :redirect
39 end
39 end
40 assert_redirected_to 'projects/ecookbook/files'
40 assert_redirected_to '/projects/ecookbook/files'
41 a = Attachment.find(:first, :order => 'created_on DESC')
41 a = Attachment.find(:first, :order => 'created_on DESC')
42 assert_equal 'testfile.txt', a.filename
42 assert_equal 'testfile.txt', a.filename
43 assert_equal Project.find(1), a.container
43 assert_equal Project.find(1), a.container
44
44
45 mail = ActionMailer::Base.deliveries.last
45 mail = ActionMailer::Base.deliveries.last
46 assert_kind_of TMail::Mail, mail
46 assert_kind_of TMail::Mail, mail
47 assert_equal "[eCookbook] New file", mail.subject
47 assert_equal "[eCookbook] New file", mail.subject
48 assert mail.body.include?('testfile.txt')
48 assert mail.body.include?('testfile.txt')
49 end
49 end
50
50
51 def test_create_version_file
51 def test_create_version_file
52 set_tmp_attachments_directory
52 set_tmp_attachments_directory
53 @request.session[:user_id] = 2
53 @request.session[:user_id] = 2
54 Setting.notified_events = ['file_added']
54 Setting.notified_events = ['file_added']
55
55
56 assert_difference 'Attachment.count' do
56 assert_difference 'Attachment.count' do
57 post :create, :project_id => 1, :version_id => '2',
57 post :create, :project_id => 1, :version_id => '2',
58 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
58 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
59 assert_response :redirect
59 assert_response :redirect
60 end
60 end
61 assert_redirected_to 'projects/ecookbook/files'
61 assert_redirected_to '/projects/ecookbook/files'
62 a = Attachment.find(:first, :order => 'created_on DESC')
62 a = Attachment.find(:first, :order => 'created_on DESC')
63 assert_equal 'testfile.txt', a.filename
63 assert_equal 'testfile.txt', a.filename
64 assert_equal Version.find(2), a.container
64 assert_equal Version.find(2), a.container
65 end
65 end
66
66
67 end
67 end
@@ -1,107 +1,107
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'groups_controller'
19 require 'groups_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class GroupsController; def rescue_action(e) raise e end; end
22 class GroupsController; def rescue_action(e) raise e end; end
23
23
24 class GroupsControllerTest < ActionController::TestCase
24 class GroupsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :groups_users
25 fixtures :projects, :users, :members, :member_roles, :groups_users
26
26
27 def setup
27 def setup
28 @controller = GroupsController.new
28 @controller = GroupsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1
32 @request.session[:user_id] = 1
33 end
33 end
34
34
35 def test_index
35 def test_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'index'
38 assert_template 'index'
39 end
39 end
40
40
41 def test_show
41 def test_show
42 get :show, :id => 10
42 get :show, :id => 10
43 assert_response :success
43 assert_response :success
44 assert_template 'show'
44 assert_template 'show'
45 end
45 end
46
46
47 def test_new
47 def test_new
48 get :new
48 get :new
49 assert_response :success
49 assert_response :success
50 assert_template 'new'
50 assert_template 'new'
51 end
51 end
52
52
53 def test_create
53 def test_create
54 assert_difference 'Group.count' do
54 assert_difference 'Group.count' do
55 post :create, :group => {:lastname => 'New group'}
55 post :create, :group => {:lastname => 'New group'}
56 end
56 end
57 assert_redirected_to 'groups'
57 assert_redirected_to '/groups'
58 end
58 end
59
59
60 def test_edit
60 def test_edit
61 get :edit, :id => 10
61 get :edit, :id => 10
62 assert_response :success
62 assert_response :success
63 assert_template 'edit'
63 assert_template 'edit'
64 end
64 end
65
65
66 def test_update
66 def test_update
67 post :update, :id => 10
67 post :update, :id => 10
68 assert_redirected_to 'groups'
68 assert_redirected_to '/groups'
69 end
69 end
70
70
71 def test_destroy
71 def test_destroy
72 assert_difference 'Group.count', -1 do
72 assert_difference 'Group.count', -1 do
73 post :destroy, :id => 10
73 post :destroy, :id => 10
74 end
74 end
75 assert_redirected_to 'groups'
75 assert_redirected_to '/groups'
76 end
76 end
77
77
78 def test_add_users
78 def test_add_users
79 assert_difference 'Group.find(10).users.count', 2 do
79 assert_difference 'Group.find(10).users.count', 2 do
80 post :add_users, :id => 10, :user_ids => ['2', '3']
80 post :add_users, :id => 10, :user_ids => ['2', '3']
81 end
81 end
82 end
82 end
83
83
84 def test_remove_user
84 def test_remove_user
85 assert_difference 'Group.find(10).users.count', -1 do
85 assert_difference 'Group.find(10).users.count', -1 do
86 post :remove_user, :id => 10, :user_id => '8'
86 post :remove_user, :id => 10, :user_id => '8'
87 end
87 end
88 end
88 end
89
89
90 def test_new_membership
90 def test_new_membership
91 assert_difference 'Group.find(10).members.count' do
91 assert_difference 'Group.find(10).members.count' do
92 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
92 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
93 end
93 end
94 end
94 end
95
95
96 def test_edit_membership
96 def test_edit_membership
97 assert_no_difference 'Group.find(10).members.count' do
97 assert_no_difference 'Group.find(10).members.count' do
98 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
98 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
99 end
99 end
100 end
100 end
101
101
102 def test_destroy_membership
102 def test_destroy_membership
103 assert_difference 'Group.find(10).members.count', -1 do
103 assert_difference 'Group.find(10).members.count', -1 do
104 post :destroy_membership, :id => 10, :membership_id => 6
104 post :destroy_membership, :id => 10, :membership_id => 6
105 end
105 end
106 end
106 end
107 end
107 end
@@ -1,124 +1,124
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2
2
3 class IssueMovesControllerTest < ActionController::TestCase
3 class IssueMovesControllerTest < ActionController::TestCase
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 User.current = nil
7 User.current = nil
8 end
8 end
9
9
10 def test_create_one_issue_to_another_project
10 def test_create_one_issue_to_another_project
11 @request.session[:user_id] = 2
11 @request.session[:user_id] = 2
12 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
12 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
13 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
13 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
14 assert_equal 2, Issue.find(1).project_id
14 assert_equal 2, Issue.find(1).project_id
15 end
15 end
16
16
17 def test_create_one_issue_to_another_project_should_follow_when_needed
17 def test_create_one_issue_to_another_project_should_follow_when_needed
18 @request.session[:user_id] = 2
18 @request.session[:user_id] = 2
19 post :create, :id => 1, :new_project_id => 2, :follow => '1'
19 post :create, :id => 1, :new_project_id => 2, :follow => '1'
20 assert_redirected_to '/issues/1'
20 assert_redirected_to '/issues/1'
21 end
21 end
22
22
23 def test_bulk_create_to_another_project
23 def test_bulk_create_to_another_project
24 @request.session[:user_id] = 2
24 @request.session[:user_id] = 2
25 post :create, :ids => [1, 2], :new_project_id => 2
25 post :create, :ids => [1, 2], :new_project_id => 2
26 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
26 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
27 # Issues moved to project 2
27 # Issues moved to project 2
28 assert_equal 2, Issue.find(1).project_id
28 assert_equal 2, Issue.find(1).project_id
29 assert_equal 2, Issue.find(2).project_id
29 assert_equal 2, Issue.find(2).project_id
30 # No tracker change
30 # No tracker change
31 assert_equal 1, Issue.find(1).tracker_id
31 assert_equal 1, Issue.find(1).tracker_id
32 assert_equal 2, Issue.find(2).tracker_id
32 assert_equal 2, Issue.find(2).tracker_id
33 end
33 end
34
34
35 def test_bulk_create_to_another_tracker
35 def test_bulk_create_to_another_tracker
36 @request.session[:user_id] = 2
36 @request.session[:user_id] = 2
37 post :create, :ids => [1, 2], :new_tracker_id => 2
37 post :create, :ids => [1, 2], :new_tracker_id => 2
38 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
38 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
39 assert_equal 2, Issue.find(1).tracker_id
39 assert_equal 2, Issue.find(1).tracker_id
40 assert_equal 2, Issue.find(2).tracker_id
40 assert_equal 2, Issue.find(2).tracker_id
41 end
41 end
42
42
43 context "#create via bulk move" do
43 context "#create via bulk move" do
44 setup do
44 setup do
45 @request.session[:user_id] = 2
45 @request.session[:user_id] = 2
46 end
46 end
47
47
48 should "allow changing the issue priority" do
48 should "allow changing the issue priority" do
49 post :create, :ids => [1, 2], :priority_id => 6
49 post :create, :ids => [1, 2], :priority_id => 6
50
50
51 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
51 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
52 assert_equal 6, Issue.find(1).priority_id
52 assert_equal 6, Issue.find(1).priority_id
53 assert_equal 6, Issue.find(2).priority_id
53 assert_equal 6, Issue.find(2).priority_id
54
54
55 end
55 end
56
56
57 should "allow adding a note when moving" do
57 should "allow adding a note when moving" do
58 post :create, :ids => [1, 2], :notes => 'Moving two issues'
58 post :create, :ids => [1, 2], :notes => 'Moving two issues'
59
59
60 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
60 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
61 assert_equal 'Moving two issues', Issue.find(1).journals.last.notes
61 assert_equal 'Moving two issues', Issue.find(1).journals.last.notes
62 assert_equal 'Moving two issues', Issue.find(2).journals.last.notes
62 assert_equal 'Moving two issues', Issue.find(2).journals.last.notes
63
63
64 end
64 end
65
65
66 end
66 end
67
67
68 def test_bulk_copy_to_another_project
68 def test_bulk_copy_to_another_project
69 @request.session[:user_id] = 2
69 @request.session[:user_id] = 2
70 assert_difference 'Issue.count', 2 do
70 assert_difference 'Issue.count', 2 do
71 assert_no_difference 'Project.find(1).issues.count' do
71 assert_no_difference 'Project.find(1).issues.count' do
72 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
72 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
73 end
73 end
74 end
74 end
75 assert_redirected_to 'projects/ecookbook/issues'
75 assert_redirected_to '/projects/ecookbook/issues'
76 end
76 end
77
77
78 context "#create via bulk copy" do
78 context "#create via bulk copy" do
79 should "allow not changing the issue's attributes" do
79 should "allow not changing the issue's attributes" do
80 @request.session[:user_id] = 2
80 @request.session[:user_id] = 2
81 issue_before_move = Issue.find(1)
81 issue_before_move = Issue.find(1)
82 assert_difference 'Issue.count', 1 do
82 assert_difference 'Issue.count', 1 do
83 assert_no_difference 'Project.find(1).issues.count' do
83 assert_no_difference 'Project.find(1).issues.count' do
84 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
84 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
85 end
85 end
86 end
86 end
87 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
87 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
88 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
88 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
89 assert_equal issue_before_move.status_id, issue_after_move.status_id
89 assert_equal issue_before_move.status_id, issue_after_move.status_id
90 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
90 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
91 end
91 end
92
92
93 should "allow changing the issue's attributes" do
93 should "allow changing the issue's attributes" do
94 # Fixes random test failure with Mysql
94 # Fixes random test failure with Mysql
95 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
95 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
96 Issue.delete_all("project_id=2")
96 Issue.delete_all("project_id=2")
97
97
98 @request.session[:user_id] = 2
98 @request.session[:user_id] = 2
99 assert_difference 'Issue.count', 2 do
99 assert_difference 'Issue.count', 2 do
100 assert_no_difference 'Project.find(1).issues.count' do
100 assert_no_difference 'Project.find(1).issues.count' do
101 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
101 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
102 end
102 end
103 end
103 end
104
104
105 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
105 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
106 assert_equal 2, copied_issues.size
106 assert_equal 2, copied_issues.size
107 copied_issues.each do |issue|
107 copied_issues.each do |issue|
108 assert_equal 2, issue.project_id, "Project is incorrect"
108 assert_equal 2, issue.project_id, "Project is incorrect"
109 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
109 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
110 assert_equal 3, issue.status_id, "Status is incorrect"
110 assert_equal 3, issue.status_id, "Status is incorrect"
111 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
111 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
112 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
112 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
113 end
113 end
114 end
114 end
115 end
115 end
116
116
117 def test_copy_to_another_project_should_follow_when_needed
117 def test_copy_to_another_project_should_follow_when_needed
118 @request.session[:user_id] = 2
118 @request.session[:user_id] = 2
119 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
119 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
120 issue = Issue.first(:order => 'id DESC')
120 issue = Issue.first(:order => 'id DESC')
121 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
121 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
122 end
122 end
123
123
124 end
124 end
@@ -1,144 +1,144
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'messages_controller'
19 require 'messages_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class MessagesController; def rescue_action(e) raise e end; end
22 class MessagesController; def rescue_action(e) raise e end; end
23
23
24 class MessagesControllerTest < ActionController::TestCase
24 class MessagesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
25 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = MessagesController.new
28 @controller = MessagesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_show
34 def test_show
35 get :show, :board_id => 1, :id => 1
35 get :show, :board_id => 1, :id => 1
36 assert_response :success
36 assert_response :success
37 assert_template 'show'
37 assert_template 'show'
38 assert_not_nil assigns(:board)
38 assert_not_nil assigns(:board)
39 assert_not_nil assigns(:project)
39 assert_not_nil assigns(:project)
40 assert_not_nil assigns(:topic)
40 assert_not_nil assigns(:topic)
41 end
41 end
42
42
43 def test_show_with_pagination
43 def test_show_with_pagination
44 message = Message.find(1)
44 message = Message.find(1)
45 assert_difference 'Message.count', 30 do
45 assert_difference 'Message.count', 30 do
46 30.times do
46 30.times do
47 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
47 message.children << Message.new(:subject => 'Reply', :content => 'Reply body', :author_id => 2, :board_id => 1)
48 end
48 end
49 end
49 end
50 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
50 get :show, :board_id => 1, :id => 1, :r => message.children.last(:order => 'id').id
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 replies = assigns(:replies)
53 replies = assigns(:replies)
54 assert_not_nil replies
54 assert_not_nil replies
55 assert !replies.include?(message.children.first(:order => 'id'))
55 assert !replies.include?(message.children.first(:order => 'id'))
56 assert replies.include?(message.children.last(:order => 'id'))
56 assert replies.include?(message.children.last(:order => 'id'))
57 end
57 end
58
58
59 def test_show_with_reply_permission
59 def test_show_with_reply_permission
60 @request.session[:user_id] = 2
60 @request.session[:user_id] = 2
61 get :show, :board_id => 1, :id => 1
61 get :show, :board_id => 1, :id => 1
62 assert_response :success
62 assert_response :success
63 assert_template 'show'
63 assert_template 'show'
64 assert_tag :div, :attributes => { :id => 'reply' },
64 assert_tag :div, :attributes => { :id => 'reply' },
65 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
65 :descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
66 end
66 end
67
67
68 def test_show_message_not_found
68 def test_show_message_not_found
69 get :show, :board_id => 1, :id => 99999
69 get :show, :board_id => 1, :id => 99999
70 assert_response 404
70 assert_response 404
71 end
71 end
72
72
73 def test_get_new
73 def test_get_new
74 @request.session[:user_id] = 2
74 @request.session[:user_id] = 2
75 get :new, :board_id => 1
75 get :new, :board_id => 1
76 assert_response :success
76 assert_response :success
77 assert_template 'new'
77 assert_template 'new'
78 end
78 end
79
79
80 def test_post_new
80 def test_post_new
81 @request.session[:user_id] = 2
81 @request.session[:user_id] = 2
82 ActionMailer::Base.deliveries.clear
82 ActionMailer::Base.deliveries.clear
83 Setting.notified_events = ['message_posted']
83 Setting.notified_events = ['message_posted']
84
84
85 post :new, :board_id => 1,
85 post :new, :board_id => 1,
86 :message => { :subject => 'Test created message',
86 :message => { :subject => 'Test created message',
87 :content => 'Message body'}
87 :content => 'Message body'}
88 message = Message.find_by_subject('Test created message')
88 message = Message.find_by_subject('Test created message')
89 assert_not_nil message
89 assert_not_nil message
90 assert_redirected_to "boards/1/topics/#{message.to_param}"
90 assert_redirected_to "/boards/1/topics/#{message.to_param}"
91 assert_equal 'Message body', message.content
91 assert_equal 'Message body', message.content
92 assert_equal 2, message.author_id
92 assert_equal 2, message.author_id
93 assert_equal 1, message.board_id
93 assert_equal 1, message.board_id
94
94
95 mail = ActionMailer::Base.deliveries.last
95 mail = ActionMailer::Base.deliveries.last
96 assert_kind_of TMail::Mail, mail
96 assert_kind_of TMail::Mail, mail
97 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
97 assert_equal "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] Test created message", mail.subject
98 assert mail.body.include?('Message body')
98 assert mail.body.include?('Message body')
99 # author
99 # author
100 assert mail.bcc.include?('jsmith@somenet.foo')
100 assert mail.bcc.include?('jsmith@somenet.foo')
101 # project member
101 # project member
102 assert mail.bcc.include?('dlopper@somenet.foo')
102 assert mail.bcc.include?('dlopper@somenet.foo')
103 end
103 end
104
104
105 def test_get_edit
105 def test_get_edit
106 @request.session[:user_id] = 2
106 @request.session[:user_id] = 2
107 get :edit, :board_id => 1, :id => 1
107 get :edit, :board_id => 1, :id => 1
108 assert_response :success
108 assert_response :success
109 assert_template 'edit'
109 assert_template 'edit'
110 end
110 end
111
111
112 def test_post_edit
112 def test_post_edit
113 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
114 post :edit, :board_id => 1, :id => 1,
114 post :edit, :board_id => 1, :id => 1,
115 :message => { :subject => 'New subject',
115 :message => { :subject => 'New subject',
116 :content => 'New body'}
116 :content => 'New body'}
117 assert_redirected_to 'boards/1/topics/1'
117 assert_redirected_to '/boards/1/topics/1'
118 message = Message.find(1)
118 message = Message.find(1)
119 assert_equal 'New subject', message.subject
119 assert_equal 'New subject', message.subject
120 assert_equal 'New body', message.content
120 assert_equal 'New body', message.content
121 end
121 end
122
122
123 def test_reply
123 def test_reply
124 @request.session[:user_id] = 2
124 @request.session[:user_id] = 2
125 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
125 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
126 reply = Message.find(:first, :order => 'id DESC')
126 reply = Message.find(:first, :order => 'id DESC')
127 assert_redirected_to "boards/1/topics/1?r=#{reply.id}"
127 assert_redirected_to "/boards/1/topics/1?r=#{reply.id}"
128 assert Message.find_by_subject('Test reply')
128 assert Message.find_by_subject('Test reply')
129 end
129 end
130
130
131 def test_destroy_topic
131 def test_destroy_topic
132 @request.session[:user_id] = 2
132 @request.session[:user_id] = 2
133 post :destroy, :board_id => 1, :id => 1
133 post :destroy, :board_id => 1, :id => 1
134 assert_redirected_to 'projects/ecookbook/boards/1'
134 assert_redirected_to '/projects/ecookbook/boards/1'
135 assert_nil Message.find_by_id(1)
135 assert_nil Message.find_by_id(1)
136 end
136 end
137
137
138 def test_quote
138 def test_quote
139 @request.session[:user_id] = 2
139 @request.session[:user_id] = 2
140 xhr :get, :quote, :board_id => 1, :id => 3
140 xhr :get, :quote, :board_id => 1, :id => 3
141 assert_response :success
141 assert_response :success
142 assert_select_rjs :show, 'reply'
142 assert_select_rjs :show, 'reply'
143 end
143 end
144 end
144 end
@@ -1,200 +1,200
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
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, :user => {:firstname => "Joe",
67 post :account, :user => {:firstname => "Joe",
68 :login => "root",
68 :login => "root",
69 :admin => 1,
69 :admin => 1,
70 :custom_field_values => {"4" => "0100562500"}}
70 :custom_field_values => {"4" => "0100562500"}}
71 assert_redirected_to 'my/account'
71 assert_redirected_to '/my/account'
72 user = User.find(2)
72 user = User.find(2)
73 assert_equal user, assigns(:user)
73 assert_equal user, assigns(:user)
74 assert_equal "Joe", user.firstname
74 assert_equal "Joe", user.firstname
75 assert_equal "jsmith", user.login
75 assert_equal "jsmith", user.login
76 assert_equal "0100562500", user.custom_value_for(4).value
76 assert_equal "0100562500", user.custom_value_for(4).value
77 assert !user.admin?
77 assert !user.admin?
78 end
78 end
79
79
80 def test_change_password
80 def test_change_password
81 get :password
81 get :password
82 assert_response :success
82 assert_response :success
83 assert_template 'password'
83 assert_template 'password'
84
84
85 # non matching password confirmation
85 # non matching password confirmation
86 post :password, :password => 'jsmith',
86 post :password, :password => 'jsmith',
87 :new_password => 'hello',
87 :new_password => 'hello',
88 :new_password_confirmation => 'hello2'
88 :new_password_confirmation => 'hello2'
89 assert_response :success
89 assert_response :success
90 assert_template 'password'
90 assert_template 'password'
91 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
91 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
92
92
93 # wrong password
93 # wrong password
94 post :password, :password => 'wrongpassword',
94 post :password, :password => 'wrongpassword',
95 :new_password => 'hello',
95 :new_password => 'hello',
96 :new_password_confirmation => 'hello'
96 :new_password_confirmation => 'hello'
97 assert_response :success
97 assert_response :success
98 assert_template 'password'
98 assert_template 'password'
99 assert_equal 'Wrong password', flash[:error]
99 assert_equal 'Wrong password', flash[:error]
100
100
101 # good password
101 # good password
102 post :password, :password => 'jsmith',
102 post :password, :password => 'jsmith',
103 :new_password => 'hello',
103 :new_password => 'hello',
104 :new_password_confirmation => 'hello'
104 :new_password_confirmation => 'hello'
105 assert_redirected_to 'my/account'
105 assert_redirected_to '/my/account'
106 assert User.try_to_login('jsmith', 'hello')
106 assert User.try_to_login('jsmith', 'hello')
107 end
107 end
108
108
109 def test_page_layout
109 def test_page_layout
110 get :page_layout
110 get :page_layout
111 assert_response :success
111 assert_response :success
112 assert_template 'page_layout'
112 assert_template 'page_layout'
113 end
113 end
114
114
115 def test_add_block
115 def test_add_block
116 xhr :post, :add_block, :block => 'issuesreportedbyme'
116 xhr :post, :add_block, :block => 'issuesreportedbyme'
117 assert_response :success
117 assert_response :success
118 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
118 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
119 end
119 end
120
120
121 def test_remove_block
121 def test_remove_block
122 xhr :post, :remove_block, :block => 'issuesassignedtome'
122 xhr :post, :remove_block, :block => 'issuesassignedtome'
123 assert_response :success
123 assert_response :success
124 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
124 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
125 end
125 end
126
126
127 def test_order_blocks
127 def test_order_blocks
128 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
128 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
129 assert_response :success
129 assert_response :success
130 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
130 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
131 end
131 end
132
132
133 context "POST to reset_rss_key" do
133 context "POST to reset_rss_key" do
134 context "with an existing rss_token" do
134 context "with an existing rss_token" do
135 setup do
135 setup do
136 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
136 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
137 post :reset_rss_key
137 post :reset_rss_key
138 end
138 end
139
139
140 should "destroy the existing token" do
140 should "destroy the existing token" do
141 assert_not_equal @previous_token_value, User.find(2).rss_key
141 assert_not_equal @previous_token_value, User.find(2).rss_key
142 end
142 end
143
143
144 should "create a new token" do
144 should "create a new token" do
145 assert User.find(2).rss_token
145 assert User.find(2).rss_token
146 end
146 end
147
147
148 should_set_the_flash_to /reset/
148 should_set_the_flash_to /reset/
149 should_redirect_to('my account') {'/my/account' }
149 should_redirect_to('my account') {'/my/account' }
150 end
150 end
151
151
152 context "with no rss_token" do
152 context "with no rss_token" do
153 setup do
153 setup do
154 assert_nil User.find(2).rss_token
154 assert_nil User.find(2).rss_token
155 post :reset_rss_key
155 post :reset_rss_key
156 end
156 end
157
157
158 should "create a new token" do
158 should "create a new token" do
159 assert User.find(2).rss_token
159 assert User.find(2).rss_token
160 end
160 end
161
161
162 should_set_the_flash_to /reset/
162 should_set_the_flash_to /reset/
163 should_redirect_to('my account') {'/my/account' }
163 should_redirect_to('my account') {'/my/account' }
164 end
164 end
165 end
165 end
166
166
167 context "POST to reset_api_key" do
167 context "POST to reset_api_key" do
168 context "with an existing api_token" do
168 context "with an existing api_token" do
169 setup do
169 setup do
170 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
170 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
171 post :reset_api_key
171 post :reset_api_key
172 end
172 end
173
173
174 should "destroy the existing token" do
174 should "destroy the existing token" do
175 assert_not_equal @previous_token_value, User.find(2).api_key
175 assert_not_equal @previous_token_value, User.find(2).api_key
176 end
176 end
177
177
178 should "create a new token" do
178 should "create a new token" do
179 assert User.find(2).api_token
179 assert User.find(2).api_token
180 end
180 end
181
181
182 should_set_the_flash_to /reset/
182 should_set_the_flash_to /reset/
183 should_redirect_to('my account') {'/my/account' }
183 should_redirect_to('my account') {'/my/account' }
184 end
184 end
185
185
186 context "with no api_token" do
186 context "with no api_token" do
187 setup do
187 setup do
188 assert_nil User.find(2).api_token
188 assert_nil User.find(2).api_token
189 post :reset_api_key
189 post :reset_api_key
190 end
190 end
191
191
192 should "create a new token" do
192 should "create a new token" do
193 assert User.find(2).api_token
193 assert User.find(2).api_token
194 end
194 end
195
195
196 should_set_the_flash_to /reset/
196 should_set_the_flash_to /reset/
197 should_redirect_to('my account') {'/my/account' }
197 should_redirect_to('my account') {'/my/account' }
198 end
198 end
199 end
199 end
200 end
200 end
@@ -1,120 +1,120
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'news_controller'
19 require 'news_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class NewsController; def rescue_action(e) raise e end; end
22 class NewsController; def rescue_action(e) raise e end; end
23
23
24 class NewsControllerTest < ActionController::TestCase
24 class NewsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
26
26
27 def setup
27 def setup
28 @controller = NewsController.new
28 @controller = NewsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
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 'index'
37 assert_template 'index'
38 assert_not_nil assigns(:newss)
38 assert_not_nil assigns(:newss)
39 assert_nil assigns(:project)
39 assert_nil assigns(:project)
40 end
40 end
41
41
42 def test_index_with_project
42 def test_index_with_project
43 get :index, :project_id => 1
43 get :index, :project_id => 1
44 assert_response :success
44 assert_response :success
45 assert_template 'index'
45 assert_template 'index'
46 assert_not_nil assigns(:newss)
46 assert_not_nil assigns(:newss)
47 end
47 end
48
48
49 def test_show
49 def test_show
50 get :show, :id => 1
50 get :show, :id => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_tag :tag => 'h2', :content => /eCookbook first release/
53 assert_tag :tag => 'h2', :content => /eCookbook first release/
54 end
54 end
55
55
56 def test_show_not_found
56 def test_show_not_found
57 get :show, :id => 999
57 get :show, :id => 999
58 assert_response 404
58 assert_response 404
59 end
59 end
60
60
61 def test_get_new
61 def test_get_new
62 @request.session[:user_id] = 2
62 @request.session[:user_id] = 2
63 get :new, :project_id => 1
63 get :new, :project_id => 1
64 assert_response :success
64 assert_response :success
65 assert_template 'new'
65 assert_template 'new'
66 end
66 end
67
67
68 def test_post_create
68 def test_post_create
69 ActionMailer::Base.deliveries.clear
69 ActionMailer::Base.deliveries.clear
70 Setting.notified_events << 'news_added'
70 Setting.notified_events << 'news_added'
71
71
72 @request.session[:user_id] = 2
72 @request.session[:user_id] = 2
73 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest',
73 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest',
74 :description => 'This is the description',
74 :description => 'This is the description',
75 :summary => '' }
75 :summary => '' }
76 assert_redirected_to 'projects/ecookbook/news'
76 assert_redirected_to '/projects/ecookbook/news'
77
77
78 news = News.find_by_title('NewsControllerTest')
78 news = News.find_by_title('NewsControllerTest')
79 assert_not_nil news
79 assert_not_nil news
80 assert_equal 'This is the description', news.description
80 assert_equal 'This is the description', news.description
81 assert_equal User.find(2), news.author
81 assert_equal User.find(2), news.author
82 assert_equal Project.find(1), news.project
82 assert_equal Project.find(1), news.project
83 assert_equal 1, ActionMailer::Base.deliveries.size
83 assert_equal 1, ActionMailer::Base.deliveries.size
84 end
84 end
85
85
86 def test_get_edit
86 def test_get_edit
87 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
88 get :edit, :id => 1
88 get :edit, :id => 1
89 assert_response :success
89 assert_response :success
90 assert_template 'edit'
90 assert_template 'edit'
91 end
91 end
92
92
93 def test_put_update
93 def test_put_update
94 @request.session[:user_id] = 2
94 @request.session[:user_id] = 2
95 put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
95 put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
96 assert_redirected_to 'news/1'
96 assert_redirected_to '/news/1'
97 news = News.find(1)
97 news = News.find(1)
98 assert_equal 'Description changed by test_post_edit', news.description
98 assert_equal 'Description changed by test_post_edit', news.description
99 end
99 end
100
100
101 def test_post_create_with_validation_failure
101 def test_post_create_with_validation_failure
102 @request.session[:user_id] = 2
102 @request.session[:user_id] = 2
103 post :create, :project_id => 1, :news => { :title => '',
103 post :create, :project_id => 1, :news => { :title => '',
104 :description => 'This is the description',
104 :description => 'This is the description',
105 :summary => '' }
105 :summary => '' }
106 assert_response :success
106 assert_response :success
107 assert_template 'new'
107 assert_template 'new'
108 assert_not_nil assigns(:news)
108 assert_not_nil assigns(:news)
109 assert assigns(:news).new_record?
109 assert assigns(:news).new_record?
110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
111 :content => /1 error/
111 :content => /1 error/
112 end
112 end
113
113
114 def test_destroy
114 def test_destroy
115 @request.session[:user_id] = 2
115 @request.session[:user_id] = 2
116 delete :destroy, :id => 1
116 delete :destroy, :id => 1
117 assert_redirected_to 'projects/ecookbook/news'
117 assert_redirected_to '/projects/ecookbook/news'
118 assert_nil News.find_by_id(1)
118 assert_nil News.find_by_id(1)
119 end
119 end
120 end
120 end
@@ -1,189 +1,189
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2
2
3 class ProjectEnumerationsControllerTest < ActionController::TestCase
3 class ProjectEnumerationsControllerTest < ActionController::TestCase
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 @request.session[:user_id] = nil
7 @request.session[:user_id] = nil
8 Setting.default_language = 'en'
8 Setting.default_language = 'en'
9 end
9 end
10
10
11 def test_update_to_override_system_activities
11 def test_update_to_override_system_activities
12 @request.session[:user_id] = 2 # manager
12 @request.session[:user_id] = 2 # manager
13 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
13 billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
14
14
15 put :update, :project_id => 1, :enumerations => {
15 put :update, :project_id => 1, :enumerations => {
16 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
16 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
17 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
17 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
18 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
18 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
19 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
19 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes
20 }
20 }
21
21
22 assert_response :redirect
22 assert_response :redirect
23 assert_redirected_to 'projects/ecookbook/settings/activities'
23 assert_redirected_to '/projects/ecookbook/settings/activities'
24
24
25 # Created project specific activities...
25 # Created project specific activities...
26 project = Project.find('ecookbook')
26 project = Project.find('ecookbook')
27
27
28 # ... Design
28 # ... Design
29 design = project.time_entry_activities.find_by_name("Design")
29 design = project.time_entry_activities.find_by_name("Design")
30 assert design, "Project activity not found"
30 assert design, "Project activity not found"
31
31
32 assert_equal 9, design.parent_id # Relate to the system activity
32 assert_equal 9, design.parent_id # Relate to the system activity
33 assert_not_equal design.parent.id, design.id # Different records
33 assert_not_equal design.parent.id, design.id # Different records
34 assert_equal design.parent.name, design.name # Same name
34 assert_equal design.parent.name, design.name # Same name
35 assert !design.active?
35 assert !design.active?
36
36
37 # ... Development
37 # ... Development
38 development = project.time_entry_activities.find_by_name("Development")
38 development = project.time_entry_activities.find_by_name("Development")
39 assert development, "Project activity not found"
39 assert development, "Project activity not found"
40
40
41 assert_equal 10, development.parent_id # Relate to the system activity
41 assert_equal 10, development.parent_id # Relate to the system activity
42 assert_not_equal development.parent.id, development.id # Different records
42 assert_not_equal development.parent.id, development.id # Different records
43 assert_equal development.parent.name, development.name # Same name
43 assert_equal development.parent.name, development.name # Same name
44 assert development.active?
44 assert development.active?
45 assert_equal "0", development.custom_value_for(billable_field).value
45 assert_equal "0", development.custom_value_for(billable_field).value
46
46
47 # ... Inactive Activity
47 # ... Inactive Activity
48 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
48 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity")
49 assert previously_inactive, "Project activity not found"
49 assert previously_inactive, "Project activity not found"
50
50
51 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
51 assert_equal 14, previously_inactive.parent_id # Relate to the system activity
52 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
52 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records
53 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
53 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name
54 assert previously_inactive.active?
54 assert previously_inactive.active?
55 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
55 assert_equal "1", previously_inactive.custom_value_for(billable_field).value
56
56
57 # ... QA
57 # ... QA
58 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
58 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
59 end
59 end
60
60
61 def test_update_will_update_project_specific_activities
61 def test_update_will_update_project_specific_activities
62 @request.session[:user_id] = 2 # manager
62 @request.session[:user_id] = 2 # manager
63
63
64 project_activity = TimeEntryActivity.new({
64 project_activity = TimeEntryActivity.new({
65 :name => 'Project Specific',
65 :name => 'Project Specific',
66 :parent => TimeEntryActivity.find(:first),
66 :parent => TimeEntryActivity.find(:first),
67 :project => Project.find(1),
67 :project => Project.find(1),
68 :active => true
68 :active => true
69 })
69 })
70 assert project_activity.save
70 assert project_activity.save
71 project_activity_two = TimeEntryActivity.new({
71 project_activity_two = TimeEntryActivity.new({
72 :name => 'Project Specific Two',
72 :name => 'Project Specific Two',
73 :parent => TimeEntryActivity.find(:last),
73 :parent => TimeEntryActivity.find(:last),
74 :project => Project.find(1),
74 :project => Project.find(1),
75 :active => true
75 :active => true
76 })
76 })
77 assert project_activity_two.save
77 assert project_activity_two.save
78
78
79
79
80 put :update, :project_id => 1, :enumerations => {
80 put :update, :project_id => 1, :enumerations => {
81 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
81 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
82 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
82 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
83 }
83 }
84
84
85 assert_response :redirect
85 assert_response :redirect
86 assert_redirected_to 'projects/ecookbook/settings/activities'
86 assert_redirected_to '/projects/ecookbook/settings/activities'
87
87
88 # Created project specific activities...
88 # Created project specific activities...
89 project = Project.find('ecookbook')
89 project = Project.find('ecookbook')
90 assert_equal 2, project.time_entry_activities.count
90 assert_equal 2, project.time_entry_activities.count
91
91
92 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
92 activity_one = project.time_entry_activities.find_by_name(project_activity.name)
93 assert activity_one, "Project activity not found"
93 assert activity_one, "Project activity not found"
94 assert_equal project_activity.id, activity_one.id
94 assert_equal project_activity.id, activity_one.id
95 assert !activity_one.active?
95 assert !activity_one.active?
96
96
97 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
97 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name)
98 assert activity_two, "Project activity not found"
98 assert activity_two, "Project activity not found"
99 assert_equal project_activity_two.id, activity_two.id
99 assert_equal project_activity_two.id, activity_two.id
100 assert !activity_two.active?
100 assert !activity_two.active?
101 end
101 end
102
102
103 def test_update_when_creating_new_activities_will_convert_existing_data
103 def test_update_when_creating_new_activities_will_convert_existing_data
104 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
104 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
105
105
106 @request.session[:user_id] = 2 # manager
106 @request.session[:user_id] = 2 # manager
107 put :update, :project_id => 1, :enumerations => {
107 put :update, :project_id => 1, :enumerations => {
108 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
108 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
109 }
109 }
110 assert_response :redirect
110 assert_response :redirect
111
111
112 # No more TimeEntries using the system activity
112 # No more TimeEntries using the system activity
113 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
113 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
114 # All TimeEntries using project activity
114 # All TimeEntries using project activity
115 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
115 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
116 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
116 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
117 end
117 end
118
118
119 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
119 def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
120 # TODO: Need to cause an exception on create but these tests
120 # TODO: Need to cause an exception on create but these tests
121 # aren't setup for mocking. Just create a record now so the
121 # aren't setup for mocking. Just create a record now so the
122 # second one is a dupicate
122 # second one is a dupicate
123 parent = TimeEntryActivity.find(9)
123 parent = TimeEntryActivity.find(9)
124 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
124 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
125 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
125 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
126
126
127 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
127 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
128 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
128 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
129
129
130 @request.session[:user_id] = 2 # manager
130 @request.session[:user_id] = 2 # manager
131 put :update, :project_id => 1, :enumerations => {
131 put :update, :project_id => 1, :enumerations => {
132 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
132 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
133 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
133 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
134 }
134 }
135 assert_response :redirect
135 assert_response :redirect
136
136
137 # TimeEntries shouldn't have been reassigned on the failed record
137 # TimeEntries shouldn't have been reassigned on the failed record
138 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
138 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
139 # TimeEntries shouldn't have been reassigned on the saved record either
139 # TimeEntries shouldn't have been reassigned on the saved record either
140 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
140 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
141 end
141 end
142
142
143 def test_destroy
143 def test_destroy
144 @request.session[:user_id] = 2 # manager
144 @request.session[:user_id] = 2 # manager
145 project_activity = TimeEntryActivity.new({
145 project_activity = TimeEntryActivity.new({
146 :name => 'Project Specific',
146 :name => 'Project Specific',
147 :parent => TimeEntryActivity.find(:first),
147 :parent => TimeEntryActivity.find(:first),
148 :project => Project.find(1),
148 :project => Project.find(1),
149 :active => true
149 :active => true
150 })
150 })
151 assert project_activity.save
151 assert project_activity.save
152 project_activity_two = TimeEntryActivity.new({
152 project_activity_two = TimeEntryActivity.new({
153 :name => 'Project Specific Two',
153 :name => 'Project Specific Two',
154 :parent => TimeEntryActivity.find(:last),
154 :parent => TimeEntryActivity.find(:last),
155 :project => Project.find(1),
155 :project => Project.find(1),
156 :active => true
156 :active => true
157 })
157 })
158 assert project_activity_two.save
158 assert project_activity_two.save
159
159
160 delete :destroy, :project_id => 1
160 delete :destroy, :project_id => 1
161 assert_response :redirect
161 assert_response :redirect
162 assert_redirected_to 'projects/ecookbook/settings/activities'
162 assert_redirected_to '/projects/ecookbook/settings/activities'
163
163
164 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
164 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
165 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
165 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id)
166 end
166 end
167
167
168 def test_destroy_should_reassign_time_entries_back_to_the_system_activity
168 def test_destroy_should_reassign_time_entries_back_to_the_system_activity
169 @request.session[:user_id] = 2 # manager
169 @request.session[:user_id] = 2 # manager
170 project_activity = TimeEntryActivity.new({
170 project_activity = TimeEntryActivity.new({
171 :name => 'Project Specific Design',
171 :name => 'Project Specific Design',
172 :parent => TimeEntryActivity.find(9),
172 :parent => TimeEntryActivity.find(9),
173 :project => Project.find(1),
173 :project => Project.find(1),
174 :active => true
174 :active => true
175 })
175 })
176 assert project_activity.save
176 assert project_activity.save
177 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
177 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
178 assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
178 assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
179
179
180 delete :destroy, :project_id => 1
180 delete :destroy, :project_id => 1
181 assert_response :redirect
181 assert_response :redirect
182 assert_redirected_to 'projects/ecookbook/settings/activities'
182 assert_redirected_to '/projects/ecookbook/settings/activities'
183
183
184 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
184 assert_nil TimeEntryActivity.find_by_id(project_activity.id)
185 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
185 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
186 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
186 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
187 end
187 end
188
188
189 end
189 end
@@ -1,460 +1,460
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < ActionController::TestCase
24 class ProjectsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 :attachments, :custom_fields, :custom_values, :time_entries
27 :attachments, :custom_fields, :custom_values, :time_entries
28
28
29 def setup
29 def setup
30 @controller = ProjectsController.new
30 @controller = ProjectsController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 @request.session[:user_id] = nil
33 @request.session[:user_id] = nil
34 Setting.default_language = 'en'
34 Setting.default_language = 'en'
35 end
35 end
36
36
37 def test_index
37 def test_index
38 get :index
38 get :index
39 assert_response :success
39 assert_response :success
40 assert_template 'index'
40 assert_template 'index'
41 assert_not_nil assigns(:projects)
41 assert_not_nil assigns(:projects)
42
42
43 assert_tag :ul, :child => {:tag => 'li',
43 assert_tag :ul, :child => {:tag => 'li',
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
44 :descendant => {:tag => 'a', :content => 'eCookbook'},
45 :child => { :tag => 'ul',
45 :child => { :tag => 'ul',
46 :descendant => { :tag => 'a',
46 :descendant => { :tag => 'a',
47 :content => 'Child of private child'
47 :content => 'Child of private child'
48 }
48 }
49 }
49 }
50 }
50 }
51
51
52 assert_no_tag :a, :content => /Private child of eCookbook/
52 assert_no_tag :a, :content => /Private child of eCookbook/
53 end
53 end
54
54
55 def test_index_atom
55 def test_index_atom
56 get :index, :format => 'atom'
56 get :index, :format => 'atom'
57 assert_response :success
57 assert_response :success
58 assert_template 'common/feed.atom.rxml'
58 assert_template 'common/feed.atom.rxml'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
59 assert_select 'feed>title', :text => 'Redmine: Latest projects'
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
61 end
61 end
62
62
63 context "#index" do
63 context "#index" do
64 context "by non-admin user with view_time_entries permission" do
64 context "by non-admin user with view_time_entries permission" do
65 setup do
65 setup do
66 @request.session[:user_id] = 3
66 @request.session[:user_id] = 3
67 end
67 end
68 should "show overall spent time link" do
68 should "show overall spent time link" do
69 get :index
69 get :index
70 assert_template 'index'
70 assert_template 'index'
71 assert_tag :a, :attributes => {:href => '/time_entries'}
71 assert_tag :a, :attributes => {:href => '/time_entries'}
72 end
72 end
73 end
73 end
74
74
75 context "by non-admin user without view_time_entries permission" do
75 context "by non-admin user without view_time_entries permission" do
76 setup do
76 setup do
77 Role.find(2).remove_permission! :view_time_entries
77 Role.find(2).remove_permission! :view_time_entries
78 Role.non_member.remove_permission! :view_time_entries
78 Role.non_member.remove_permission! :view_time_entries
79 Role.anonymous.remove_permission! :view_time_entries
79 Role.anonymous.remove_permission! :view_time_entries
80 @request.session[:user_id] = 3
80 @request.session[:user_id] = 3
81 end
81 end
82 should "not show overall spent time link" do
82 should "not show overall spent time link" do
83 get :index
83 get :index
84 assert_template 'index'
84 assert_template 'index'
85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
85 assert_no_tag :a, :attributes => {:href => '/time_entries'}
86 end
86 end
87 end
87 end
88 end
88 end
89
89
90 context "#new" do
90 context "#new" do
91 context "by admin user" do
91 context "by admin user" do
92 setup do
92 setup do
93 @request.session[:user_id] = 1
93 @request.session[:user_id] = 1
94 end
94 end
95
95
96 should "accept get" do
96 should "accept get" do
97 get :new
97 get :new
98 assert_response :success
98 assert_response :success
99 assert_template 'new'
99 assert_template 'new'
100 end
100 end
101
101
102 end
102 end
103
103
104 context "by non-admin user with add_project permission" do
104 context "by non-admin user with add_project permission" do
105 setup do
105 setup do
106 Role.non_member.add_permission! :add_project
106 Role.non_member.add_permission! :add_project
107 @request.session[:user_id] = 9
107 @request.session[:user_id] = 9
108 end
108 end
109
109
110 should "accept get" do
110 should "accept get" do
111 get :new
111 get :new
112 assert_response :success
112 assert_response :success
113 assert_template 'new'
113 assert_template 'new'
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
114 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}
115 end
115 end
116 end
116 end
117
117
118 context "by non-admin user with add_subprojects permission" do
118 context "by non-admin user with add_subprojects permission" do
119 setup do
119 setup do
120 Role.find(1).remove_permission! :add_project
120 Role.find(1).remove_permission! :add_project
121 Role.find(1).add_permission! :add_subprojects
121 Role.find(1).add_permission! :add_subprojects
122 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
123 end
123 end
124
124
125 should "accept get" do
125 should "accept get" do
126 get :new, :parent_id => 'ecookbook'
126 get :new, :parent_id => 'ecookbook'
127 assert_response :success
127 assert_response :success
128 assert_template 'new'
128 assert_template 'new'
129 # parent project selected
129 # parent project selected
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
130 assert_tag :select, :attributes => {:name => 'project[parent_id]'},
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
131 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
132 # no empty value
132 # no empty value
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
133 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'},
134 :child => {:tag => 'option', :attributes => {:value => ''}}
134 :child => {:tag => 'option', :attributes => {:value => ''}}
135 end
135 end
136 end
136 end
137
137
138 end
138 end
139
139
140 context "POST :create" do
140 context "POST :create" do
141 context "by admin user" do
141 context "by admin user" do
142 setup do
142 setup do
143 @request.session[:user_id] = 1
143 @request.session[:user_id] = 1
144 end
144 end
145
145
146 should "create a new project" do
146 should "create a new project" do
147 post :create, :project => { :name => "blog",
147 post :create, :project => { :name => "blog",
148 :description => "weblog",
148 :description => "weblog",
149 :identifier => "blog",
149 :identifier => "blog",
150 :is_public => 1,
150 :is_public => 1,
151 :custom_field_values => { '3' => 'Beta' }
151 :custom_field_values => { '3' => 'Beta' }
152 }
152 }
153 assert_redirected_to '/projects/blog/settings'
153 assert_redirected_to '/projects/blog/settings'
154
154
155 project = Project.find_by_name('blog')
155 project = Project.find_by_name('blog')
156 assert_kind_of Project, project
156 assert_kind_of Project, project
157 assert_equal 'weblog', project.description
157 assert_equal 'weblog', project.description
158 assert_equal true, project.is_public?
158 assert_equal true, project.is_public?
159 assert_nil project.parent
159 assert_nil project.parent
160 end
160 end
161
161
162 should "create a new subproject" do
162 should "create a new subproject" do
163 post :create, :project => { :name => "blog",
163 post :create, :project => { :name => "blog",
164 :description => "weblog",
164 :description => "weblog",
165 :identifier => "blog",
165 :identifier => "blog",
166 :is_public => 1,
166 :is_public => 1,
167 :custom_field_values => { '3' => 'Beta' },
167 :custom_field_values => { '3' => 'Beta' },
168 :parent_id => 1
168 :parent_id => 1
169 }
169 }
170 assert_redirected_to '/projects/blog/settings'
170 assert_redirected_to '/projects/blog/settings'
171
171
172 project = Project.find_by_name('blog')
172 project = Project.find_by_name('blog')
173 assert_kind_of Project, project
173 assert_kind_of Project, project
174 assert_equal Project.find(1), project.parent
174 assert_equal Project.find(1), project.parent
175 end
175 end
176 end
176 end
177
177
178 context "by non-admin user with add_project permission" do
178 context "by non-admin user with add_project permission" do
179 setup do
179 setup do
180 Role.non_member.add_permission! :add_project
180 Role.non_member.add_permission! :add_project
181 @request.session[:user_id] = 9
181 @request.session[:user_id] = 9
182 end
182 end
183
183
184 should "accept create a Project" do
184 should "accept create a Project" do
185 post :create, :project => { :name => "blog",
185 post :create, :project => { :name => "blog",
186 :description => "weblog",
186 :description => "weblog",
187 :identifier => "blog",
187 :identifier => "blog",
188 :is_public => 1,
188 :is_public => 1,
189 :custom_field_values => { '3' => 'Beta' }
189 :custom_field_values => { '3' => 'Beta' }
190 }
190 }
191
191
192 assert_redirected_to '/projects/blog/settings'
192 assert_redirected_to '/projects/blog/settings'
193
193
194 project = Project.find_by_name('blog')
194 project = Project.find_by_name('blog')
195 assert_kind_of Project, project
195 assert_kind_of Project, project
196 assert_equal 'weblog', project.description
196 assert_equal 'weblog', project.description
197 assert_equal true, project.is_public?
197 assert_equal true, project.is_public?
198
198
199 # User should be added as a project member
199 # User should be added as a project member
200 assert User.find(9).member_of?(project)
200 assert User.find(9).member_of?(project)
201 assert_equal 1, project.members.size
201 assert_equal 1, project.members.size
202 end
202 end
203
203
204 should "fail with parent_id" do
204 should "fail with parent_id" do
205 assert_no_difference 'Project.count' do
205 assert_no_difference 'Project.count' do
206 post :create, :project => { :name => "blog",
206 post :create, :project => { :name => "blog",
207 :description => "weblog",
207 :description => "weblog",
208 :identifier => "blog",
208 :identifier => "blog",
209 :is_public => 1,
209 :is_public => 1,
210 :custom_field_values => { '3' => 'Beta' },
210 :custom_field_values => { '3' => 'Beta' },
211 :parent_id => 1
211 :parent_id => 1
212 }
212 }
213 end
213 end
214 assert_response :success
214 assert_response :success
215 project = assigns(:project)
215 project = assigns(:project)
216 assert_kind_of Project, project
216 assert_kind_of Project, project
217 assert_not_nil project.errors.on(:parent_id)
217 assert_not_nil project.errors.on(:parent_id)
218 end
218 end
219 end
219 end
220
220
221 context "by non-admin user with add_subprojects permission" do
221 context "by non-admin user with add_subprojects permission" do
222 setup do
222 setup do
223 Role.find(1).remove_permission! :add_project
223 Role.find(1).remove_permission! :add_project
224 Role.find(1).add_permission! :add_subprojects
224 Role.find(1).add_permission! :add_subprojects
225 @request.session[:user_id] = 2
225 @request.session[:user_id] = 2
226 end
226 end
227
227
228 should "create a project with a parent_id" do
228 should "create a project with a parent_id" do
229 post :create, :project => { :name => "blog",
229 post :create, :project => { :name => "blog",
230 :description => "weblog",
230 :description => "weblog",
231 :identifier => "blog",
231 :identifier => "blog",
232 :is_public => 1,
232 :is_public => 1,
233 :custom_field_values => { '3' => 'Beta' },
233 :custom_field_values => { '3' => 'Beta' },
234 :parent_id => 1
234 :parent_id => 1
235 }
235 }
236 assert_redirected_to '/projects/blog/settings'
236 assert_redirected_to '/projects/blog/settings'
237 project = Project.find_by_name('blog')
237 project = Project.find_by_name('blog')
238 end
238 end
239
239
240 should "fail without parent_id" do
240 should "fail without parent_id" do
241 assert_no_difference 'Project.count' do
241 assert_no_difference 'Project.count' do
242 post :create, :project => { :name => "blog",
242 post :create, :project => { :name => "blog",
243 :description => "weblog",
243 :description => "weblog",
244 :identifier => "blog",
244 :identifier => "blog",
245 :is_public => 1,
245 :is_public => 1,
246 :custom_field_values => { '3' => 'Beta' }
246 :custom_field_values => { '3' => 'Beta' }
247 }
247 }
248 end
248 end
249 assert_response :success
249 assert_response :success
250 project = assigns(:project)
250 project = assigns(:project)
251 assert_kind_of Project, project
251 assert_kind_of Project, project
252 assert_not_nil project.errors.on(:parent_id)
252 assert_not_nil project.errors.on(:parent_id)
253 end
253 end
254
254
255 should "fail with unauthorized parent_id" do
255 should "fail with unauthorized parent_id" do
256 assert !User.find(2).member_of?(Project.find(6))
256 assert !User.find(2).member_of?(Project.find(6))
257 assert_no_difference 'Project.count' do
257 assert_no_difference 'Project.count' do
258 post :create, :project => { :name => "blog",
258 post :create, :project => { :name => "blog",
259 :description => "weblog",
259 :description => "weblog",
260 :identifier => "blog",
260 :identifier => "blog",
261 :is_public => 1,
261 :is_public => 1,
262 :custom_field_values => { '3' => 'Beta' },
262 :custom_field_values => { '3' => 'Beta' },
263 :parent_id => 6
263 :parent_id => 6
264 }
264 }
265 end
265 end
266 assert_response :success
266 assert_response :success
267 project = assigns(:project)
267 project = assigns(:project)
268 assert_kind_of Project, project
268 assert_kind_of Project, project
269 assert_not_nil project.errors.on(:parent_id)
269 assert_not_nil project.errors.on(:parent_id)
270 end
270 end
271 end
271 end
272 end
272 end
273
273
274 def test_show_by_id
274 def test_show_by_id
275 get :show, :id => 1
275 get :show, :id => 1
276 assert_response :success
276 assert_response :success
277 assert_template 'show'
277 assert_template 'show'
278 assert_not_nil assigns(:project)
278 assert_not_nil assigns(:project)
279 end
279 end
280
280
281 def test_show_by_identifier
281 def test_show_by_identifier
282 get :show, :id => 'ecookbook'
282 get :show, :id => 'ecookbook'
283 assert_response :success
283 assert_response :success
284 assert_template 'show'
284 assert_template 'show'
285 assert_not_nil assigns(:project)
285 assert_not_nil assigns(:project)
286 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
286 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
287
287
288 assert_tag 'li', :content => /Development status/
288 assert_tag 'li', :content => /Development status/
289 end
289 end
290
290
291 def test_show_should_not_display_hidden_custom_fields
291 def test_show_should_not_display_hidden_custom_fields
292 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
292 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
293 get :show, :id => 'ecookbook'
293 get :show, :id => 'ecookbook'
294 assert_response :success
294 assert_response :success
295 assert_template 'show'
295 assert_template 'show'
296 assert_not_nil assigns(:project)
296 assert_not_nil assigns(:project)
297
297
298 assert_no_tag 'li', :content => /Development status/
298 assert_no_tag 'li', :content => /Development status/
299 end
299 end
300
300
301 def test_show_should_not_fail_when_custom_values_are_nil
301 def test_show_should_not_fail_when_custom_values_are_nil
302 project = Project.find_by_identifier('ecookbook')
302 project = Project.find_by_identifier('ecookbook')
303 project.custom_values.first.update_attribute(:value, nil)
303 project.custom_values.first.update_attribute(:value, nil)
304 get :show, :id => 'ecookbook'
304 get :show, :id => 'ecookbook'
305 assert_response :success
305 assert_response :success
306 assert_template 'show'
306 assert_template 'show'
307 assert_not_nil assigns(:project)
307 assert_not_nil assigns(:project)
308 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
308 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
309 end
309 end
310
310
311 def show_archived_project_should_be_denied
311 def show_archived_project_should_be_denied
312 project = Project.find_by_identifier('ecookbook')
312 project = Project.find_by_identifier('ecookbook')
313 project.archive!
313 project.archive!
314
314
315 get :show, :id => 'ecookbook'
315 get :show, :id => 'ecookbook'
316 assert_response 403
316 assert_response 403
317 assert_nil assigns(:project)
317 assert_nil assigns(:project)
318 assert_tag :tag => 'p', :content => /archived/
318 assert_tag :tag => 'p', :content => /archived/
319 end
319 end
320
320
321 def test_private_subprojects_hidden
321 def test_private_subprojects_hidden
322 get :show, :id => 'ecookbook'
322 get :show, :id => 'ecookbook'
323 assert_response :success
323 assert_response :success
324 assert_template 'show'
324 assert_template 'show'
325 assert_no_tag :tag => 'a', :content => /Private child/
325 assert_no_tag :tag => 'a', :content => /Private child/
326 end
326 end
327
327
328 def test_private_subprojects_visible
328 def test_private_subprojects_visible
329 @request.session[:user_id] = 2 # manager who is a member of the private subproject
329 @request.session[:user_id] = 2 # manager who is a member of the private subproject
330 get :show, :id => 'ecookbook'
330 get :show, :id => 'ecookbook'
331 assert_response :success
331 assert_response :success
332 assert_template 'show'
332 assert_template 'show'
333 assert_tag :tag => 'a', :content => /Private child/
333 assert_tag :tag => 'a', :content => /Private child/
334 end
334 end
335
335
336 def test_settings
336 def test_settings
337 @request.session[:user_id] = 2 # manager
337 @request.session[:user_id] = 2 # manager
338 get :settings, :id => 1
338 get :settings, :id => 1
339 assert_response :success
339 assert_response :success
340 assert_template 'settings'
340 assert_template 'settings'
341 end
341 end
342
342
343 def test_update
343 def test_update
344 @request.session[:user_id] = 2 # manager
344 @request.session[:user_id] = 2 # manager
345 post :update, :id => 1, :project => {:name => 'Test changed name',
345 post :update, :id => 1, :project => {:name => 'Test changed name',
346 :issue_custom_field_ids => ['']}
346 :issue_custom_field_ids => ['']}
347 assert_redirected_to 'projects/ecookbook/settings'
347 assert_redirected_to '/projects/ecookbook/settings'
348 project = Project.find(1)
348 project = Project.find(1)
349 assert_equal 'Test changed name', project.name
349 assert_equal 'Test changed name', project.name
350 end
350 end
351
351
352 def test_get_destroy
352 def test_get_destroy
353 @request.session[:user_id] = 1 # admin
353 @request.session[:user_id] = 1 # admin
354 get :destroy, :id => 1
354 get :destroy, :id => 1
355 assert_response :success
355 assert_response :success
356 assert_template 'destroy'
356 assert_template 'destroy'
357 assert_not_nil Project.find_by_id(1)
357 assert_not_nil Project.find_by_id(1)
358 end
358 end
359
359
360 def test_post_destroy
360 def test_post_destroy
361 @request.session[:user_id] = 1 # admin
361 @request.session[:user_id] = 1 # admin
362 post :destroy, :id => 1, :confirm => 1
362 post :destroy, :id => 1, :confirm => 1
363 assert_redirected_to 'admin/projects'
363 assert_redirected_to '/admin/projects'
364 assert_nil Project.find_by_id(1)
364 assert_nil Project.find_by_id(1)
365 end
365 end
366
366
367 def test_archive
367 def test_archive
368 @request.session[:user_id] = 1 # admin
368 @request.session[:user_id] = 1 # admin
369 post :archive, :id => 1
369 post :archive, :id => 1
370 assert_redirected_to 'admin/projects'
370 assert_redirected_to '/admin/projects'
371 assert !Project.find(1).active?
371 assert !Project.find(1).active?
372 end
372 end
373
373
374 def test_unarchive
374 def test_unarchive
375 @request.session[:user_id] = 1 # admin
375 @request.session[:user_id] = 1 # admin
376 Project.find(1).archive
376 Project.find(1).archive
377 post :unarchive, :id => 1
377 post :unarchive, :id => 1
378 assert_redirected_to 'admin/projects'
378 assert_redirected_to '/admin/projects'
379 assert Project.find(1).active?
379 assert Project.find(1).active?
380 end
380 end
381
381
382 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
382 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
383 CustomField.delete_all
383 CustomField.delete_all
384 parent = nil
384 parent = nil
385 6.times do |i|
385 6.times do |i|
386 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
386 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
387 p.set_parent!(parent)
387 p.set_parent!(parent)
388 get :show, :id => p
388 get :show, :id => p
389 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
389 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
390 :children => { :count => [i, 3].min,
390 :children => { :count => [i, 3].min,
391 :only => { :tag => 'a' } }
391 :only => { :tag => 'a' } }
392
392
393 parent = p
393 parent = p
394 end
394 end
395 end
395 end
396
396
397 def test_copy_with_project
397 def test_copy_with_project
398 @request.session[:user_id] = 1 # admin
398 @request.session[:user_id] = 1 # admin
399 get :copy, :id => 1
399 get :copy, :id => 1
400 assert_response :success
400 assert_response :success
401 assert_template 'copy'
401 assert_template 'copy'
402 assert assigns(:project)
402 assert assigns(:project)
403 assert_equal Project.find(1).description, assigns(:project).description
403 assert_equal Project.find(1).description, assigns(:project).description
404 assert_nil assigns(:project).id
404 assert_nil assigns(:project).id
405 end
405 end
406
406
407 def test_copy_without_project
407 def test_copy_without_project
408 @request.session[:user_id] = 1 # admin
408 @request.session[:user_id] = 1 # admin
409 get :copy
409 get :copy
410 assert_response :redirect
410 assert_response :redirect
411 assert_redirected_to :controller => 'admin', :action => 'projects'
411 assert_redirected_to :controller => 'admin', :action => 'projects'
412 end
412 end
413
413
414 context "POST :copy" do
414 context "POST :copy" do
415 should "TODO: test the rest of the method"
415 should "TODO: test the rest of the method"
416
416
417 should "redirect to the project settings when successful" do
417 should "redirect to the project settings when successful" do
418 @request.session[:user_id] = 1 # admin
418 @request.session[:user_id] = 1 # admin
419 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
419 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
420 assert_response :redirect
420 assert_response :redirect
421 assert_redirected_to :controller => 'projects', :action => 'settings'
421 assert_redirected_to :controller => 'projects', :action => 'settings'
422 end
422 end
423 end
423 end
424
424
425 def test_jump_should_redirect_to_active_tab
425 def test_jump_should_redirect_to_active_tab
426 get :show, :id => 1, :jump => 'issues'
426 get :show, :id => 1, :jump => 'issues'
427 assert_redirected_to 'projects/ecookbook/issues'
427 assert_redirected_to '/projects/ecookbook/issues'
428 end
428 end
429
429
430 def test_jump_should_not_redirect_to_inactive_tab
430 def test_jump_should_not_redirect_to_inactive_tab
431 get :show, :id => 3, :jump => 'documents'
431 get :show, :id => 3, :jump => 'documents'
432 assert_response :success
432 assert_response :success
433 assert_template 'show'
433 assert_template 'show'
434 end
434 end
435
435
436 def test_jump_should_not_redirect_to_unknown_tab
436 def test_jump_should_not_redirect_to_unknown_tab
437 get :show, :id => 3, :jump => 'foobar'
437 get :show, :id => 3, :jump => 'foobar'
438 assert_response :success
438 assert_response :success
439 assert_template 'show'
439 assert_template 'show'
440 end
440 end
441
441
442 # A hook that is manually registered later
442 # A hook that is manually registered later
443 class ProjectBasedTemplate < Redmine::Hook::ViewListener
443 class ProjectBasedTemplate < Redmine::Hook::ViewListener
444 def view_layouts_base_html_head(context)
444 def view_layouts_base_html_head(context)
445 # Adds a project stylesheet
445 # Adds a project stylesheet
446 stylesheet_link_tag(context[:project].identifier) if context[:project]
446 stylesheet_link_tag(context[:project].identifier) if context[:project]
447 end
447 end
448 end
448 end
449 # Don't use this hook now
449 # Don't use this hook now
450 Redmine::Hook.clear_listeners
450 Redmine::Hook.clear_listeners
451
451
452 def test_hook_response
452 def test_hook_response
453 Redmine::Hook.add_listener(ProjectBasedTemplate)
453 Redmine::Hook.add_listener(ProjectBasedTemplate)
454 get :show, :id => 1
454 get :show, :id => 1
455 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
455 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
456 :parent => {:tag => 'head'}
456 :parent => {:tag => 'head'}
457
457
458 Redmine::Hook.clear_listeners
458 Redmine::Hook.clear_listeners
459 end
459 end
460 end
460 end
@@ -1,105 +1,105
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesControllerTest < ActionController::TestCase
24 class RepositoriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26
26
27 def setup
27 def setup
28 @controller = RepositoriesController.new
28 @controller = RepositoriesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_revisions
34 def test_revisions
35 get :revisions, :id => 1
35 get :revisions, :id => 1
36 assert_response :success
36 assert_response :success
37 assert_template 'revisions'
37 assert_template 'revisions'
38 assert_not_nil assigns(:changesets)
38 assert_not_nil assigns(:changesets)
39 end
39 end
40
40
41 def test_revision
41 def test_revision
42 get :revision, :id => 1, :rev => 1
42 get :revision, :id => 1, :rev => 1
43 assert_response :success
43 assert_response :success
44 assert_not_nil assigns(:changeset)
44 assert_not_nil assigns(:changeset)
45 assert_equal "1", assigns(:changeset).revision
45 assert_equal "1", assigns(:changeset).revision
46 end
46 end
47
47
48 def test_revision_with_before_nil_and_afer_normal
48 def test_revision_with_before_nil_and_afer_normal
49 get :revision, {:id => 1, :rev => 1}
49 get :revision, {:id => 1, :rev => 1}
50 assert_response :success
50 assert_response :success
51 assert_template 'revision'
51 assert_template 'revision'
52 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
52 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
53 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
53 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
54 }
54 }
55 assert_tag :tag => "div", :attributes => { :class => "contextual" },
55 assert_tag :tag => "div", :attributes => { :class => "contextual" },
56 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
56 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
57 }
57 }
58 end
58 end
59
59
60 def test_graph_commits_per_month
60 def test_graph_commits_per_month
61 get :graph, :id => 1, :graph => 'commits_per_month'
61 get :graph, :id => 1, :graph => 'commits_per_month'
62 assert_response :success
62 assert_response :success
63 assert_equal 'image/svg+xml', @response.content_type
63 assert_equal 'image/svg+xml', @response.content_type
64 end
64 end
65
65
66 def test_graph_commits_per_author
66 def test_graph_commits_per_author
67 get :graph, :id => 1, :graph => 'commits_per_author'
67 get :graph, :id => 1, :graph => 'commits_per_author'
68 assert_response :success
68 assert_response :success
69 assert_equal 'image/svg+xml', @response.content_type
69 assert_equal 'image/svg+xml', @response.content_type
70 end
70 end
71
71
72 def test_committers
72 def test_committers
73 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
74 # add a commit with an unknown user
74 # add a commit with an unknown user
75 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
75 Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
76
76
77 get :committers, :id => 1
77 get :committers, :id => 1
78 assert_response :success
78 assert_response :success
79 assert_template 'committers'
79 assert_template 'committers'
80
80
81 assert_tag :td, :content => 'dlopper',
81 assert_tag :td, :content => 'dlopper',
82 :sibling => { :tag => 'td',
82 :sibling => { :tag => 'td',
83 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
83 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
84 :child => { :tag => 'option', :content => 'Dave Lopper',
84 :child => { :tag => 'option', :content => 'Dave Lopper',
85 :attributes => { :value => '3', :selected => 'selected' }}}}
85 :attributes => { :value => '3', :selected => 'selected' }}}}
86 assert_tag :td, :content => 'foo',
86 assert_tag :td, :content => 'foo',
87 :sibling => { :tag => 'td',
87 :sibling => { :tag => 'td',
88 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
88 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
89 assert_no_tag :td, :content => 'foo',
89 assert_no_tag :td, :content => 'foo',
90 :sibling => { :tag => 'td',
90 :sibling => { :tag => 'td',
91 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
91 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
92 end
92 end
93
93
94 def test_map_committers
94 def test_map_committers
95 @request.session[:user_id] = 2
95 @request.session[:user_id] = 2
96 # add a commit with an unknown user
96 # add a commit with an unknown user
97 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
97 c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
98
98
99 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
99 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
100 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
100 post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
101 assert_redirected_to 'projects/ecookbook/repository/committers'
101 assert_redirected_to '/projects/ecookbook/repository/committers'
102 assert_equal User.find(2), c.reload.user
102 assert_equal User.find(2), c.reload.user
103 end
103 end
104 end
104 end
105 end
105 end
@@ -1,180 +1,180
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'roles_controller'
19 require 'roles_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RolesController; def rescue_action(e) raise e end; end
22 class RolesController; def rescue_action(e) raise e end; end
23
23
24 class RolesControllerTest < ActionController::TestCase
24 class RolesControllerTest < ActionController::TestCase
25 fixtures :roles, :users, :members, :member_roles, :workflows
25 fixtures :roles, :users, :members, :member_roles, :workflows
26
26
27 def setup
27 def setup
28 @controller = RolesController.new
28 @controller = RolesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
33 end
33 end
34
34
35 def test_get_index
35 def test_get_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'index'
38 assert_template 'index'
39
39
40 assert_not_nil assigns(:roles)
40 assert_not_nil assigns(:roles)
41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
42
42
43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
44 :content => 'Manager'
44 :content => 'Manager'
45 end
45 end
46
46
47 def test_get_new
47 def test_get_new
48 get :new
48 get :new
49 assert_response :success
49 assert_response :success
50 assert_template 'new'
50 assert_template 'new'
51 end
51 end
52
52
53 def test_post_new_with_validaton_failure
53 def test_post_new_with_validaton_failure
54 post :new, :role => {:name => '',
54 post :new, :role => {:name => '',
55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
56 :assignable => '0'}
56 :assignable => '0'}
57
57
58 assert_response :success
58 assert_response :success
59 assert_template 'new'
59 assert_template 'new'
60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
61 end
61 end
62
62
63 def test_post_new_without_workflow_copy
63 def test_post_new_without_workflow_copy
64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
66 :assignable => '0'}
66 :assignable => '0'}
67
67
68 assert_redirected_to 'roles'
68 assert_redirected_to '/roles'
69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
70 assert_not_nil role
70 assert_not_nil role
71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
72 assert !role.assignable?
72 assert !role.assignable?
73 end
73 end
74
74
75 def test_post_new_with_workflow_copy
75 def test_post_new_with_workflow_copy
76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
78 :assignable => '0'},
78 :assignable => '0'},
79 :copy_workflow_from => '1'
79 :copy_workflow_from => '1'
80
80
81 assert_redirected_to 'roles'
81 assert_redirected_to '/roles'
82 role = Role.find_by_name('RoleWithWorkflowCopy')
82 role = Role.find_by_name('RoleWithWorkflowCopy')
83 assert_not_nil role
83 assert_not_nil role
84 assert_equal Role.find(1).workflows.size, role.workflows.size
84 assert_equal Role.find(1).workflows.size, role.workflows.size
85 end
85 end
86
86
87 def test_get_edit
87 def test_get_edit
88 get :edit, :id => 1
88 get :edit, :id => 1
89 assert_response :success
89 assert_response :success
90 assert_template 'edit'
90 assert_template 'edit'
91 assert_equal Role.find(1), assigns(:role)
91 assert_equal Role.find(1), assigns(:role)
92 end
92 end
93
93
94 def test_post_edit
94 def test_post_edit
95 post :edit, :id => 1,
95 post :edit, :id => 1,
96 :role => {:name => 'Manager',
96 :role => {:name => 'Manager',
97 :permissions => ['edit_project', ''],
97 :permissions => ['edit_project', ''],
98 :assignable => '0'}
98 :assignable => '0'}
99
99
100 assert_redirected_to 'roles'
100 assert_redirected_to '/roles'
101 role = Role.find(1)
101 role = Role.find(1)
102 assert_equal [:edit_project], role.permissions
102 assert_equal [:edit_project], role.permissions
103 end
103 end
104
104
105 def test_destroy
105 def test_destroy
106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
107 assert r.save
107 assert r.save
108
108
109 post :destroy, :id => r
109 post :destroy, :id => r
110 assert_redirected_to 'roles'
110 assert_redirected_to '/roles'
111 assert_nil Role.find_by_id(r.id)
111 assert_nil Role.find_by_id(r.id)
112 end
112 end
113
113
114 def test_destroy_role_in_use
114 def test_destroy_role_in_use
115 post :destroy, :id => 1
115 post :destroy, :id => 1
116 assert_redirected_to 'roles'
116 assert_redirected_to '/roles'
117 assert flash[:error] == 'This role is in use and can not be deleted.'
117 assert flash[:error] == 'This role is in use and can not be deleted.'
118 assert_not_nil Role.find_by_id(1)
118 assert_not_nil Role.find_by_id(1)
119 end
119 end
120
120
121 def test_get_report
121 def test_get_report
122 get :report
122 get :report
123 assert_response :success
123 assert_response :success
124 assert_template 'report'
124 assert_template 'report'
125
125
126 assert_not_nil assigns(:roles)
126 assert_not_nil assigns(:roles)
127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
128
128
129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
130 :name => 'permissions[3][]',
130 :name => 'permissions[3][]',
131 :value => 'add_issues',
131 :value => 'add_issues',
132 :checked => 'checked' }
132 :checked => 'checked' }
133
133
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
135 :name => 'permissions[3][]',
135 :name => 'permissions[3][]',
136 :value => 'delete_issues',
136 :value => 'delete_issues',
137 :checked => nil }
137 :checked => nil }
138 end
138 end
139
139
140 def test_post_report
140 def test_post_report
141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
142 assert_redirected_to 'roles'
142 assert_redirected_to '/roles'
143
143
144 assert_equal [:edit_issues], Role.find(1).permissions
144 assert_equal [:edit_issues], Role.find(1).permissions
145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
146 assert Role.find(2).permissions.empty?
146 assert Role.find(2).permissions.empty?
147 end
147 end
148
148
149 def test_clear_all_permissions
149 def test_clear_all_permissions
150 post :report, :permissions => { '0' => '' }
150 post :report, :permissions => { '0' => '' }
151 assert_redirected_to 'roles'
151 assert_redirected_to '/roles'
152 assert Role.find(1).permissions.empty?
152 assert Role.find(1).permissions.empty?
153 end
153 end
154
154
155 def test_move_highest
155 def test_move_highest
156 post :edit, :id => 3, :role => {:move_to => 'highest'}
156 post :edit, :id => 3, :role => {:move_to => 'highest'}
157 assert_redirected_to 'roles'
157 assert_redirected_to '/roles'
158 assert_equal 1, Role.find(3).position
158 assert_equal 1, Role.find(3).position
159 end
159 end
160
160
161 def test_move_higher
161 def test_move_higher
162 position = Role.find(3).position
162 position = Role.find(3).position
163 post :edit, :id => 3, :role => {:move_to => 'higher'}
163 post :edit, :id => 3, :role => {:move_to => 'higher'}
164 assert_redirected_to 'roles'
164 assert_redirected_to '/roles'
165 assert_equal position - 1, Role.find(3).position
165 assert_equal position - 1, Role.find(3).position
166 end
166 end
167
167
168 def test_move_lower
168 def test_move_lower
169 position = Role.find(2).position
169 position = Role.find(2).position
170 post :edit, :id => 2, :role => {:move_to => 'lower'}
170 post :edit, :id => 2, :role => {:move_to => 'lower'}
171 assert_redirected_to 'roles'
171 assert_redirected_to '/roles'
172 assert_equal position + 1, Role.find(2).position
172 assert_equal position + 1, Role.find(2).position
173 end
173 end
174
174
175 def test_move_lowest
175 def test_move_lowest
176 post :edit, :id => 2, :role => {:move_to => 'lowest'}
176 post :edit, :id => 2, :role => {:move_to => 'lowest'}
177 assert_redirected_to 'roles'
177 assert_redirected_to '/roles'
178 assert_equal Role.count, Role.find(2).position
178 assert_equal Role.count, Role.find(2).position
179 end
179 end
180 end
180 end
@@ -1,147 +1,147
1 require File.dirname(__FILE__) + '/../test_helper'
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'search_controller'
2 require 'search_controller'
3
3
4 # Re-raise errors caught by the controller.
4 # Re-raise errors caught by the controller.
5 class SearchController; def rescue_action(e) raise e end; end
5 class SearchController; def rescue_action(e) raise e end; end
6
6
7 class SearchControllerTest < ActionController::TestCase
7 class SearchControllerTest < ActionController::TestCase
8 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
8 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
9 :issues, :trackers, :issue_statuses,
9 :issues, :trackers, :issue_statuses,
10 :custom_fields, :custom_values,
10 :custom_fields, :custom_values,
11 :repositories, :changesets
11 :repositories, :changesets
12
12
13 def setup
13 def setup
14 @controller = SearchController.new
14 @controller = SearchController.new
15 @request = ActionController::TestRequest.new
15 @request = ActionController::TestRequest.new
16 @response = ActionController::TestResponse.new
16 @response = ActionController::TestResponse.new
17 User.current = nil
17 User.current = nil
18 end
18 end
19
19
20 def test_search_for_projects
20 def test_search_for_projects
21 get :index
21 get :index
22 assert_response :success
22 assert_response :success
23 assert_template 'index'
23 assert_template 'index'
24
24
25 get :index, :q => "cook"
25 get :index, :q => "cook"
26 assert_response :success
26 assert_response :success
27 assert_template 'index'
27 assert_template 'index'
28 assert assigns(:results).include?(Project.find(1))
28 assert assigns(:results).include?(Project.find(1))
29 end
29 end
30
30
31 def test_search_all_projects
31 def test_search_all_projects
32 get :index, :q => 'recipe subproject commit', :submit => 'Search'
32 get :index, :q => 'recipe subproject commit', :submit => 'Search'
33 assert_response :success
33 assert_response :success
34 assert_template 'index'
34 assert_template 'index'
35
35
36 assert assigns(:results).include?(Issue.find(2))
36 assert assigns(:results).include?(Issue.find(2))
37 assert assigns(:results).include?(Issue.find(5))
37 assert assigns(:results).include?(Issue.find(5))
38 assert assigns(:results).include?(Changeset.find(101))
38 assert assigns(:results).include?(Changeset.find(101))
39 assert_tag :dt, :attributes => { :class => /issue/ },
39 assert_tag :dt, :attributes => { :class => /issue/ },
40 :child => { :tag => 'a', :content => /Add ingredients categories/ },
40 :child => { :tag => 'a', :content => /Add ingredients categories/ },
41 :sibling => { :tag => 'dd', :content => /should be classified by categories/ }
41 :sibling => { :tag => 'dd', :content => /should be classified by categories/ }
42
42
43 assert assigns(:results_by_type).is_a?(Hash)
43 assert assigns(:results_by_type).is_a?(Hash)
44 assert_equal 5, assigns(:results_by_type)['changesets']
44 assert_equal 5, assigns(:results_by_type)['changesets']
45 assert_tag :a, :content => 'Changesets (5)'
45 assert_tag :a, :content => 'Changesets (5)'
46 end
46 end
47
47
48 def test_search_issues
48 def test_search_issues
49 get :index, :q => 'issue', :issues => 1
49 get :index, :q => 'issue', :issues => 1
50 assert_response :success
50 assert_response :success
51 assert_template 'index'
51 assert_template 'index'
52
52
53 assert assigns(:results).include?(Issue.find(8))
53 assert assigns(:results).include?(Issue.find(8))
54 assert assigns(:results).include?(Issue.find(5))
54 assert assigns(:results).include?(Issue.find(5))
55 assert_tag :dt, :attributes => { :class => /issue closed/ },
55 assert_tag :dt, :attributes => { :class => /issue closed/ },
56 :child => { :tag => 'a', :content => /Closed/ }
56 :child => { :tag => 'a', :content => /Closed/ }
57 end
57 end
58
58
59 def test_search_project_and_subprojects
59 def test_search_project_and_subprojects
60 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
60 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
61 assert_response :success
61 assert_response :success
62 assert_template 'index'
62 assert_template 'index'
63 assert assigns(:results).include?(Issue.find(1))
63 assert assigns(:results).include?(Issue.find(1))
64 assert assigns(:results).include?(Issue.find(5))
64 assert assigns(:results).include?(Issue.find(5))
65 end
65 end
66
66
67 def test_search_without_searchable_custom_fields
67 def test_search_without_searchable_custom_fields
68 CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
68 CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
69
69
70 get :index, :id => 1
70 get :index, :id => 1
71 assert_response :success
71 assert_response :success
72 assert_template 'index'
72 assert_template 'index'
73 assert_not_nil assigns(:project)
73 assert_not_nil assigns(:project)
74
74
75 get :index, :id => 1, :q => "can"
75 get :index, :id => 1, :q => "can"
76 assert_response :success
76 assert_response :success
77 assert_template 'index'
77 assert_template 'index'
78 end
78 end
79
79
80 def test_search_with_searchable_custom_fields
80 def test_search_with_searchable_custom_fields
81 get :index, :id => 1, :q => "stringforcustomfield"
81 get :index, :id => 1, :q => "stringforcustomfield"
82 assert_response :success
82 assert_response :success
83 results = assigns(:results)
83 results = assigns(:results)
84 assert_not_nil results
84 assert_not_nil results
85 assert_equal 1, results.size
85 assert_equal 1, results.size
86 assert results.include?(Issue.find(3))
86 assert results.include?(Issue.find(3))
87 end
87 end
88
88
89 def test_search_all_words
89 def test_search_all_words
90 # 'all words' is on by default
90 # 'all words' is on by default
91 get :index, :id => 1, :q => 'recipe updating saving'
91 get :index, :id => 1, :q => 'recipe updating saving'
92 results = assigns(:results)
92 results = assigns(:results)
93 assert_not_nil results
93 assert_not_nil results
94 assert_equal 1, results.size
94 assert_equal 1, results.size
95 assert results.include?(Issue.find(3))
95 assert results.include?(Issue.find(3))
96 end
96 end
97
97
98 def test_search_one_of_the_words
98 def test_search_one_of_the_words
99 get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
99 get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
100 results = assigns(:results)
100 results = assigns(:results)
101 assert_not_nil results
101 assert_not_nil results
102 assert_equal 3, results.size
102 assert_equal 3, results.size
103 assert results.include?(Issue.find(3))
103 assert results.include?(Issue.find(3))
104 end
104 end
105
105
106 def test_search_titles_only_without_result
106 def test_search_titles_only_without_result
107 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
107 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
108 results = assigns(:results)
108 results = assigns(:results)
109 assert_not_nil results
109 assert_not_nil results
110 assert_equal 0, results.size
110 assert_equal 0, results.size
111 end
111 end
112
112
113 def test_search_titles_only
113 def test_search_titles_only
114 get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
114 get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
115 results = assigns(:results)
115 results = assigns(:results)
116 assert_not_nil results
116 assert_not_nil results
117 assert_equal 2, results.size
117 assert_equal 2, results.size
118 end
118 end
119
119
120 def test_search_with_invalid_project_id
120 def test_search_with_invalid_project_id
121 get :index, :id => 195, :q => 'recipe'
121 get :index, :id => 195, :q => 'recipe'
122 assert_response 404
122 assert_response 404
123 assert_nil assigns(:results)
123 assert_nil assigns(:results)
124 end
124 end
125
125
126 def test_quick_jump_to_issue
126 def test_quick_jump_to_issue
127 # issue of a public project
127 # issue of a public project
128 get :index, :q => "3"
128 get :index, :q => "3"
129 assert_redirected_to 'issues/3'
129 assert_redirected_to '/issues/3'
130
130
131 # issue of a private project
131 # issue of a private project
132 get :index, :q => "4"
132 get :index, :q => "4"
133 assert_response :success
133 assert_response :success
134 assert_template 'index'
134 assert_template 'index'
135 end
135 end
136
136
137 def test_large_integer
137 def test_large_integer
138 get :index, :q => '4615713488'
138 get :index, :q => '4615713488'
139 assert_response :success
139 assert_response :success
140 assert_template 'index'
140 assert_template 'index'
141 end
141 end
142
142
143 def test_tokens_with_quotes
143 def test_tokens_with_quotes
144 get :index, :id => 1, :q => '"good bye" hello "bye bye"'
144 get :index, :id => 1, :q => '"good bye" hello "bye bye"'
145 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
145 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
146 end
146 end
147 end
147 end
@@ -1,59 +1,59
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'settings_controller'
19 require 'settings_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class SettingsController; def rescue_action(e) raise e end; end
22 class SettingsController; def rescue_action(e) raise e end; end
23
23
24 class SettingsControllerTest < ActionController::TestCase
24 class SettingsControllerTest < ActionController::TestCase
25 fixtures :users
25 fixtures :users
26
26
27 def setup
27 def setup
28 @controller = SettingsController.new
28 @controller = SettingsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
33 end
33 end
34
34
35 def test_index
35 def test_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'edit'
38 assert_template 'edit'
39 end
39 end
40
40
41 def test_get_edit
41 def test_get_edit
42 get :edit
42 get :edit
43 assert_response :success
43 assert_response :success
44 assert_template 'edit'
44 assert_template 'edit'
45 end
45 end
46
46
47 def test_post_edit_notifications
47 def test_post_edit_notifications
48 post :edit, :settings => {:mail_from => 'functional@test.foo',
48 post :edit, :settings => {:mail_from => 'functional@test.foo',
49 :bcc_recipients => '0',
49 :bcc_recipients => '0',
50 :notified_events => %w(issue_added issue_updated news_added),
50 :notified_events => %w(issue_added issue_updated news_added),
51 :emails_footer => 'Test footer'
51 :emails_footer => 'Test footer'
52 }
52 }
53 assert_redirected_to 'settings/edit'
53 assert_redirected_to '/settings/edit'
54 assert_equal 'functional@test.foo', Setting.mail_from
54 assert_equal 'functional@test.foo', Setting.mail_from
55 assert !Setting.bcc_recipients?
55 assert !Setting.bcc_recipients?
56 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
56 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
57 assert_equal 'Test footer', Setting.emails_footer
57 assert_equal 'Test footer', Setting.emails_footer
58 end
58 end
59 end
59 end
@@ -1,206 +1,206
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__)}/../test_helper"
18 require "#{File.dirname(__FILE__)}/../test_helper"
19
19
20 begin
20 begin
21 require 'mocha'
21 require 'mocha'
22 rescue
22 rescue
23 # Won't run some tests
23 # Won't run some tests
24 end
24 end
25
25
26 class AccountTest < ActionController::IntegrationTest
26 class AccountTest < ActionController::IntegrationTest
27 fixtures :users, :roles
27 fixtures :users, :roles
28
28
29 # Replace this with your real tests.
29 # Replace this with your real tests.
30 def test_login
30 def test_login
31 get "my/page"
31 get "my/page"
32 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
32 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
33 log_user('jsmith', 'jsmith')
33 log_user('jsmith', 'jsmith')
34
34
35 get "my/account"
35 get "my/account"
36 assert_response :success
36 assert_response :success
37 assert_template "my/account"
37 assert_template "my/account"
38 end
38 end
39
39
40 def test_autologin
40 def test_autologin
41 user = User.find(1)
41 user = User.find(1)
42 Setting.autologin = "7"
42 Setting.autologin = "7"
43 Token.delete_all
43 Token.delete_all
44
44
45 # User logs in with 'autologin' checked
45 # User logs in with 'autologin' checked
46 post '/login', :username => user.login, :password => 'admin', :autologin => 1
46 post '/login', :username => user.login, :password => 'admin', :autologin => 1
47 assert_redirected_to 'my/page'
47 assert_redirected_to '/my/page'
48 token = Token.find :first
48 token = Token.find :first
49 assert_not_nil token
49 assert_not_nil token
50 assert_equal user, token.user
50 assert_equal user, token.user
51 assert_equal 'autologin', token.action
51 assert_equal 'autologin', token.action
52 assert_equal user.id, session[:user_id]
52 assert_equal user.id, session[:user_id]
53 assert_equal token.value, cookies['autologin']
53 assert_equal token.value, cookies['autologin']
54
54
55 # Session is cleared
55 # Session is cleared
56 reset!
56 reset!
57 User.current = nil
57 User.current = nil
58 # Clears user's last login timestamp
58 # Clears user's last login timestamp
59 user.update_attribute :last_login_on, nil
59 user.update_attribute :last_login_on, nil
60 assert_nil user.reload.last_login_on
60 assert_nil user.reload.last_login_on
61
61
62 # User comes back with his autologin cookie
62 # User comes back with his autologin cookie
63 cookies[:autologin] = token.value
63 cookies[:autologin] = token.value
64 get '/my/page'
64 get '/my/page'
65 assert_response :success
65 assert_response :success
66 assert_template 'my/page'
66 assert_template 'my/page'
67 assert_equal user.id, session[:user_id]
67 assert_equal user.id, session[:user_id]
68 assert_not_nil user.reload.last_login_on
68 assert_not_nil user.reload.last_login_on
69 assert user.last_login_on.utc > 10.second.ago.utc
69 assert user.last_login_on.utc > 10.second.ago.utc
70 end
70 end
71
71
72 def test_lost_password
72 def test_lost_password
73 Token.delete_all
73 Token.delete_all
74
74
75 get "account/lost_password"
75 get "account/lost_password"
76 assert_response :success
76 assert_response :success
77 assert_template "account/lost_password"
77 assert_template "account/lost_password"
78
78
79 post "account/lost_password", :mail => 'jSmith@somenet.foo'
79 post "account/lost_password", :mail => 'jSmith@somenet.foo'
80 assert_redirected_to "/login"
80 assert_redirected_to "/login"
81
81
82 token = Token.find(:first)
82 token = Token.find(:first)
83 assert_equal 'recovery', token.action
83 assert_equal 'recovery', token.action
84 assert_equal 'jsmith@somenet.foo', token.user.mail
84 assert_equal 'jsmith@somenet.foo', token.user.mail
85 assert !token.expired?
85 assert !token.expired?
86
86
87 get "account/lost_password", :token => token.value
87 get "account/lost_password", :token => token.value
88 assert_response :success
88 assert_response :success
89 assert_template "account/password_recovery"
89 assert_template "account/password_recovery"
90
90
91 post "account/lost_password", :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'newpass'
91 post "account/lost_password", :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'newpass'
92 assert_redirected_to "/login"
92 assert_redirected_to "/login"
93 assert_equal 'Password was successfully updated.', flash[:notice]
93 assert_equal 'Password was successfully updated.', flash[:notice]
94
94
95 log_user('jsmith', 'newpass')
95 log_user('jsmith', 'newpass')
96 assert_equal 0, Token.count
96 assert_equal 0, Token.count
97 end
97 end
98
98
99 def test_register_with_automatic_activation
99 def test_register_with_automatic_activation
100 Setting.self_registration = '3'
100 Setting.self_registration = '3'
101
101
102 get 'account/register'
102 get 'account/register'
103 assert_response :success
103 assert_response :success
104 assert_template 'account/register'
104 assert_template 'account/register'
105
105
106 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
106 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
107 :password => "newpass", :password_confirmation => "newpass"
107 :password => "newpass", :password_confirmation => "newpass"
108 assert_redirected_to 'my/account'
108 assert_redirected_to '/my/account'
109 follow_redirect!
109 follow_redirect!
110 assert_response :success
110 assert_response :success
111 assert_template 'my/account'
111 assert_template 'my/account'
112
112
113 user = User.find_by_login('newuser')
113 user = User.find_by_login('newuser')
114 assert_not_nil user
114 assert_not_nil user
115 assert user.active?
115 assert user.active?
116 assert_not_nil user.last_login_on
116 assert_not_nil user.last_login_on
117 end
117 end
118
118
119 def test_register_with_manual_activation
119 def test_register_with_manual_activation
120 Setting.self_registration = '2'
120 Setting.self_registration = '2'
121
121
122 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
122 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
123 :password => "newpass", :password_confirmation => "newpass"
123 :password => "newpass", :password_confirmation => "newpass"
124 assert_redirected_to '/login'
124 assert_redirected_to '/login'
125 assert !User.find_by_login('newuser').active?
125 assert !User.find_by_login('newuser').active?
126 end
126 end
127
127
128 def test_register_with_email_activation
128 def test_register_with_email_activation
129 Setting.self_registration = '1'
129 Setting.self_registration = '1'
130 Token.delete_all
130 Token.delete_all
131
131
132 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
132 post 'account/register', :user => {:login => "newuser", :language => "en", :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar"},
133 :password => "newpass", :password_confirmation => "newpass"
133 :password => "newpass", :password_confirmation => "newpass"
134 assert_redirected_to '/login'
134 assert_redirected_to '/login'
135 assert !User.find_by_login('newuser').active?
135 assert !User.find_by_login('newuser').active?
136
136
137 token = Token.find(:first)
137 token = Token.find(:first)
138 assert_equal 'register', token.action
138 assert_equal 'register', token.action
139 assert_equal 'newuser@foo.bar', token.user.mail
139 assert_equal 'newuser@foo.bar', token.user.mail
140 assert !token.expired?
140 assert !token.expired?
141
141
142 get 'account/activate', :token => token.value
142 get 'account/activate', :token => token.value
143 assert_redirected_to '/login'
143 assert_redirected_to '/login'
144 log_user('newuser', 'newpass')
144 log_user('newuser', 'newpass')
145 end
145 end
146
146
147 if Object.const_defined?(:Mocha)
147 if Object.const_defined?(:Mocha)
148
148
149 def test_onthefly_registration
149 def test_onthefly_registration
150 # disable registration
150 # disable registration
151 Setting.self_registration = '0'
151 Setting.self_registration = '0'
152 AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66})
152 AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66})
153
153
154 post 'account/login', :username => 'foo', :password => 'bar'
154 post 'account/login', :username => 'foo', :password => 'bar'
155 assert_redirected_to 'my/page'
155 assert_redirected_to '/my/page'
156
156
157 user = User.find_by_login('foo')
157 user = User.find_by_login('foo')
158 assert user.is_a?(User)
158 assert user.is_a?(User)
159 assert_equal 66, user.auth_source_id
159 assert_equal 66, user.auth_source_id
160 assert user.hashed_password.blank?
160 assert user.hashed_password.blank?
161 end
161 end
162
162
163 def test_onthefly_registration_with_invalid_attributes
163 def test_onthefly_registration_with_invalid_attributes
164 # disable registration
164 # disable registration
165 Setting.self_registration = '0'
165 Setting.self_registration = '0'
166 AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
166 AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
167
167
168 post 'account/login', :username => 'foo', :password => 'bar'
168 post 'account/login', :username => 'foo', :password => 'bar'
169 assert_response :success
169 assert_response :success
170 assert_template 'account/register'
170 assert_template 'account/register'
171 assert_tag :input, :attributes => { :name => 'user[firstname]', :value => '' }
171 assert_tag :input, :attributes => { :name => 'user[firstname]', :value => '' }
172 assert_tag :input, :attributes => { :name => 'user[lastname]', :value => 'Smith' }
172 assert_tag :input, :attributes => { :name => 'user[lastname]', :value => 'Smith' }
173 assert_no_tag :input, :attributes => { :name => 'user[login]' }
173 assert_no_tag :input, :attributes => { :name => 'user[login]' }
174 assert_no_tag :input, :attributes => { :name => 'user[password]' }
174 assert_no_tag :input, :attributes => { :name => 'user[password]' }
175
175
176 post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
176 post 'account/register', :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
177 assert_redirected_to '/my/account'
177 assert_redirected_to '/my/account'
178
178
179 user = User.find_by_login('foo')
179 user = User.find_by_login('foo')
180 assert user.is_a?(User)
180 assert user.is_a?(User)
181 assert_equal 66, user.auth_source_id
181 assert_equal 66, user.auth_source_id
182 assert user.hashed_password.blank?
182 assert user.hashed_password.blank?
183 end
183 end
184
184
185 def test_login_and_logout_should_clear_session
185 def test_login_and_logout_should_clear_session
186 get '/login'
186 get '/login'
187 sid = session[:session_id]
187 sid = session[:session_id]
188
188
189 post '/login', :username => 'admin', :password => 'admin'
189 post '/login', :username => 'admin', :password => 'admin'
190 assert_redirected_to 'my/page'
190 assert_redirected_to '/my/page'
191 assert_not_equal sid, session[:session_id], "login should reset session"
191 assert_not_equal sid, session[:session_id], "login should reset session"
192 assert_equal 1, session[:user_id]
192 assert_equal 1, session[:user_id]
193 sid = session[:session_id]
193 sid = session[:session_id]
194
194
195 get '/'
195 get '/'
196 assert_equal sid, session[:session_id]
196 assert_equal sid, session[:session_id]
197
197
198 get '/logout'
198 get '/logout'
199 assert_not_equal sid, session[:session_id], "logout should reset session"
199 assert_not_equal sid, session[:session_id], "logout should reset session"
200 assert_nil session[:user_id]
200 assert_nil session[:user_id]
201 end
201 end
202
202
203 else
203 else
204 puts 'Mocha is missing. Skipping tests.'
204 puts 'Mocha is missing. Skipping tests.'
205 end
205 end
206 end
206 end
@@ -1,129 +1,129
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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.dirname(__FILE__)}/../test_helper"
18 require "#{File.dirname(__FILE__)}/../test_helper"
19
19
20 class IssuesTest < ActionController::IntegrationTest
20 class IssuesTest < ActionController::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users,
22 :users,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :trackers,
25 :trackers,
26 :projects_trackers,
26 :projects_trackers,
27 :enabled_modules,
27 :enabled_modules,
28 :issue_statuses,
28 :issue_statuses,
29 :issues,
29 :issues,
30 :enumerations,
30 :enumerations,
31 :custom_fields,
31 :custom_fields,
32 :custom_values,
32 :custom_values,
33 :custom_fields_trackers
33 :custom_fields_trackers
34
34
35 # create an issue
35 # create an issue
36 def test_add_issue
36 def test_add_issue
37 log_user('jsmith', 'jsmith')
37 log_user('jsmith', 'jsmith')
38 get 'projects/1/issues/new', :tracker_id => '1'
38 get 'projects/1/issues/new', :tracker_id => '1'
39 assert_response :success
39 assert_response :success
40 assert_template 'issues/new'
40 assert_template 'issues/new'
41
41
42 post 'projects/1/issues', :tracker_id => "1",
42 post 'projects/1/issues', :tracker_id => "1",
43 :issue => { :start_date => "2006-12-26",
43 :issue => { :start_date => "2006-12-26",
44 :priority_id => "4",
44 :priority_id => "4",
45 :subject => "new test issue",
45 :subject => "new test issue",
46 :category_id => "",
46 :category_id => "",
47 :description => "new issue",
47 :description => "new issue",
48 :done_ratio => "0",
48 :done_ratio => "0",
49 :due_date => "",
49 :due_date => "",
50 :assigned_to_id => "" },
50 :assigned_to_id => "" },
51 :custom_fields => {'2' => 'Value for field 2'}
51 :custom_fields => {'2' => 'Value for field 2'}
52 # find created issue
52 # find created issue
53 issue = Issue.find_by_subject("new test issue")
53 issue = Issue.find_by_subject("new test issue")
54 assert_kind_of Issue, issue
54 assert_kind_of Issue, issue
55
55
56 # check redirection
56 # check redirection
57 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
57 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
58 follow_redirect!
58 follow_redirect!
59 assert_equal issue, assigns(:issue)
59 assert_equal issue, assigns(:issue)
60
60
61 # check issue attributes
61 # check issue attributes
62 assert_equal 'jsmith', issue.author.login
62 assert_equal 'jsmith', issue.author.login
63 assert_equal 1, issue.project.id
63 assert_equal 1, issue.project.id
64 assert_equal 1, issue.status.id
64 assert_equal 1, issue.status.id
65 end
65 end
66
66
67 # add then remove 2 attachments to an issue
67 # add then remove 2 attachments to an issue
68 def test_issue_attachements
68 def test_issue_attachements
69 log_user('jsmith', 'jsmith')
69 log_user('jsmith', 'jsmith')
70 set_tmp_attachments_directory
70 set_tmp_attachments_directory
71
71
72 put 'issues/1',
72 put 'issues/1',
73 :notes => 'Some notes',
73 :notes => 'Some notes',
74 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
74 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
75 assert_redirected_to "issues/1"
75 assert_redirected_to "/issues/1"
76
76
77 # make sure attachment was saved
77 # make sure attachment was saved
78 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
78 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
79 assert_kind_of Attachment, attachment
79 assert_kind_of Attachment, attachment
80 assert_equal Issue.find(1), attachment.container
80 assert_equal Issue.find(1), attachment.container
81 assert_equal 'This is an attachment', attachment.description
81 assert_equal 'This is an attachment', attachment.description
82 # verify the size of the attachment stored in db
82 # verify the size of the attachment stored in db
83 #assert_equal file_data_1.length, attachment.filesize
83 #assert_equal file_data_1.length, attachment.filesize
84 # verify that the attachment was written to disk
84 # verify that the attachment was written to disk
85 assert File.exist?(attachment.diskfile)
85 assert File.exist?(attachment.diskfile)
86
86
87 # remove the attachments
87 # remove the attachments
88 Issue.find(1).attachments.each(&:destroy)
88 Issue.find(1).attachments.each(&:destroy)
89 assert_equal 0, Issue.find(1).attachments.length
89 assert_equal 0, Issue.find(1).attachments.length
90 end
90 end
91
91
92 def test_other_formats_links_on_get_index
92 def test_other_formats_links_on_get_index
93 get '/projects/ecookbook/issues'
93 get '/projects/ecookbook/issues'
94
94
95 %w(Atom PDF CSV).each do |format|
95 %w(Atom PDF CSV).each do |format|
96 assert_tag :a, :content => format,
96 assert_tag :a, :content => format,
97 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
97 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
98 :rel => 'nofollow' }
98 :rel => 'nofollow' }
99 end
99 end
100 end
100 end
101
101
102 def test_other_formats_links_on_post_index_without_project_id_in_url
102 def test_other_formats_links_on_post_index_without_project_id_in_url
103 post '/issues', :project_id => 'ecookbook'
103 post '/issues', :project_id => 'ecookbook'
104
104
105 %w(Atom PDF CSV).each do |format|
105 %w(Atom PDF CSV).each do |format|
106 assert_tag :a, :content => format,
106 assert_tag :a, :content => format,
107 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
107 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
108 :rel => 'nofollow' }
108 :rel => 'nofollow' }
109 end
109 end
110 end
110 end
111
111
112 def test_pagination_links_on_get_index
112 def test_pagination_links_on_get_index
113 Setting.per_page_options = '2'
113 Setting.per_page_options = '2'
114 get '/projects/ecookbook/issues'
114 get '/projects/ecookbook/issues'
115
115
116 assert_tag :a, :content => '2',
116 assert_tag :a, :content => '2',
117 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
117 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
118
118
119 end
119 end
120
120
121 def test_pagination_links_on_post_index_without_project_id_in_url
121 def test_pagination_links_on_post_index_without_project_id_in_url
122 Setting.per_page_options = '2'
122 Setting.per_page_options = '2'
123 post '/issues', :project_id => 'ecookbook'
123 post '/issues', :project_id => 'ecookbook'
124
124
125 assert_tag :a, :content => '2',
125 assert_tag :a, :content => '2',
126 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
126 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
127
127
128 end
128 end
129 end
129 end
@@ -1,44 +1,44
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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.dirname(__FILE__)}/../test_helper"
18 require "#{File.dirname(__FILE__)}/../test_helper"
19
19
20 class ProjectsTest < ActionController::IntegrationTest
20 class ProjectsTest < ActionController::IntegrationTest
21 fixtures :projects, :users, :members
21 fixtures :projects, :users, :members
22
22
23 def test_archive_project
23 def test_archive_project
24 subproject = Project.find(1).children.first
24 subproject = Project.find(1).children.first
25 log_user("admin", "admin")
25 log_user("admin", "admin")
26 get "admin/projects"
26 get "admin/projects"
27 assert_response :success
27 assert_response :success
28 assert_template "admin/projects"
28 assert_template "admin/projects"
29 post "projects/archive", :id => 1
29 post "projects/archive", :id => 1
30 assert_redirected_to "admin/projects"
30 assert_redirected_to "/admin/projects"
31 assert !Project.find(1).active?
31 assert !Project.find(1).active?
32
32
33 get 'projects/1'
33 get 'projects/1'
34 assert_response 403
34 assert_response 403
35 get "projects/#{subproject.id}"
35 get "projects/#{subproject.id}"
36 assert_response 403
36 assert_response 403
37
37
38 post "projects/unarchive", :id => 1
38 post "projects/unarchive", :id => 1
39 assert_redirected_to "admin/projects"
39 assert_redirected_to "/admin/projects"
40 assert Project.find(1).active?
40 assert Project.find(1).active?
41 get "projects/1"
41 get "projects/1"
42 assert_response :success
42 assert_response :success
43 end
43 end
44 end
44 end
General Comments 0
You need to be logged in to leave comments. Login now