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