Mercurial > hg > soundsoftware-site
comparison test/unit/user_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 | 19 |
20 class UserTest < ActiveSupport::TestCase | 20 class UserTest < ActiveSupport::TestCase |
21 fixtures :users, :members, :projects, :roles, :member_roles, :auth_sources | 21 fixtures :users, :members, :projects, :roles, :member_roles, :auth_sources, |
22 :trackers, :issue_statuses, | |
23 :projects_trackers, | |
24 :watchers, | |
25 :issue_categories, :enumerations, :issues, | |
26 :journals, :journal_details, | |
27 :groups_users, | |
28 :enabled_modules, | |
29 :workflows | |
22 | 30 |
23 def setup | 31 def setup |
24 @admin = User.find(1) | 32 @admin = User.find(1) |
25 @jsmith = User.find(2) | 33 @jsmith = User.find(2) |
26 @dlopper = User.find(3) | 34 @dlopper = User.find(3) |
29 test 'object_daddy creation' do | 37 test 'object_daddy creation' do |
30 User.generate_with_protected!(:firstname => 'Testing connection') | 38 User.generate_with_protected!(:firstname => 'Testing connection') |
31 User.generate_with_protected!(:firstname => 'Testing connection') | 39 User.generate_with_protected!(:firstname => 'Testing connection') |
32 assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'}) | 40 assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'}) |
33 end | 41 end |
34 | 42 |
35 def test_truth | 43 def test_truth |
36 assert_kind_of User, @jsmith | 44 assert_kind_of User, @jsmith |
37 end | 45 end |
38 | 46 |
39 def test_mail_should_be_stripped | 47 def test_mail_should_be_stripped |
40 u = User.new | 48 u = User.new |
41 u.mail = " foo@bar.com " | 49 u.mail = " foo@bar.com " |
42 assert_equal "foo@bar.com", u.mail | 50 assert_equal "foo@bar.com", u.mail |
43 end | 51 end |
44 | 52 |
53 def test_mail_validation | |
54 u = User.new | |
55 u.mail = '' | |
56 assert !u.valid? | |
57 assert_equal I18n.translate('activerecord.errors.messages.blank'), u.errors.on(:mail) | |
58 end | |
59 | |
45 def test_create | 60 def test_create |
46 user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | 61 user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
47 | 62 |
48 user.login = "jsmith" | 63 user.login = "jsmith" |
49 user.password, user.password_confirmation = "password", "password" | 64 user.password, user.password_confirmation = "password", "password" |
50 # login uniqueness | 65 # login uniqueness |
51 assert !user.save | 66 assert !user.save |
52 assert_equal 1, user.errors.count | 67 assert_equal 1, user.errors.count |
53 | 68 |
54 user.login = "newuser" | 69 user.login = "newuser" |
55 user.password, user.password_confirmation = "passwd", "password" | 70 user.password, user.password_confirmation = "passwd", "password" |
56 # password confirmation | 71 # password confirmation |
57 assert !user.save | 72 assert !user.save |
58 assert_equal 1, user.errors.count | 73 assert_equal 1, user.errors.count |
70 @user2 = User.generate_with_protected! | 85 @user2 = User.generate_with_protected! |
71 assert_equal 'all', @user2.mail_notification | 86 assert_equal 'all', @user2.mail_notification |
72 end | 87 end |
73 end | 88 end |
74 end | 89 end |
75 | 90 |
76 context "User.login" do | 91 context "User.login" do |
77 should "be case-insensitive." do | 92 should "be case-insensitive." do |
78 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | 93 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
79 u.login = 'newuser' | 94 u.login = 'newuser' |
80 u.password, u.password_confirmation = "password", "password" | 95 u.password, u.password_confirmation = "password", "password" |
81 assert u.save | 96 assert u.save |
82 | 97 |
83 u = User.new(:firstname => "Similar", :lastname => "User", :mail => "similaruser@somenet.foo") | 98 u = User.new(:firstname => "Similar", :lastname => "User", :mail => "similaruser@somenet.foo") |
84 u.login = 'NewUser' | 99 u.login = 'NewUser' |
85 u.password, u.password_confirmation = "password", "password" | 100 u.password, u.password_confirmation = "password", "password" |
86 assert !u.save | 101 assert !u.save |
87 assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:login) | 102 assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:login) |
91 def test_mail_uniqueness_should_not_be_case_sensitive | 106 def test_mail_uniqueness_should_not_be_case_sensitive |
92 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | 107 u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
93 u.login = 'newuser1' | 108 u.login = 'newuser1' |
94 u.password, u.password_confirmation = "password", "password" | 109 u.password, u.password_confirmation = "password", "password" |
95 assert u.save | 110 assert u.save |
96 | 111 |
97 u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo") | 112 u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo") |
98 u.login = 'newuser2' | 113 u.login = 'newuser2' |
99 u.password, u.password_confirmation = "password", "password" | 114 u.password, u.password_confirmation = "password", "password" |
100 assert !u.save | 115 assert !u.save |
101 assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail) | 116 assert_equal I18n.translate('activerecord.errors.messages.taken'), u.errors.on(:mail) |
106 @admin.login = "john" | 121 @admin.login = "john" |
107 assert @admin.save, @admin.errors.full_messages.join("; ") | 122 assert @admin.save, @admin.errors.full_messages.join("; ") |
108 @admin.reload | 123 @admin.reload |
109 assert_equal "john", @admin.login | 124 assert_equal "john", @admin.login |
110 end | 125 end |
111 | 126 |
112 def test_destroy_should_delete_members_and_roles | 127 def test_destroy_should_delete_members_and_roles |
113 members = Member.find_all_by_user_id(2) | 128 members = Member.find_all_by_user_id(2) |
114 ms = members.size | 129 ms = members.size |
115 rs = members.collect(&:roles).flatten.size | 130 rs = members.collect(&:roles).flatten.size |
116 | 131 |
117 assert_difference 'Member.count', - ms do | 132 assert_difference 'Member.count', - ms do |
118 assert_difference 'MemberRole.count', - rs do | 133 assert_difference 'MemberRole.count', - rs do |
119 User.find(2).destroy | 134 User.find(2).destroy |
120 end | 135 end |
121 end | 136 end |
122 | 137 |
123 assert_nil User.find_by_id(2) | 138 assert_nil User.find_by_id(2) |
124 assert Member.find_all_by_user_id(2).empty? | 139 assert Member.find_all_by_user_id(2).empty? |
125 end | 140 end |
126 | 141 |
127 def test_destroy_should_update_attachments | 142 def test_destroy_should_update_attachments |
128 attachment = Attachment.create!(:container => Project.find(1), | 143 attachment = Attachment.create!(:container => Project.find(1), |
129 :file => uploaded_test_file("testfile.txt", "text/plain"), | 144 :file => uploaded_test_file("testfile.txt", "text/plain"), |
130 :author_id => 2) | 145 :author_id => 2) |
131 | 146 |
132 User.find(2).destroy | 147 User.find(2).destroy |
133 assert_nil User.find_by_id(2) | 148 assert_nil User.find_by_id(2) |
134 assert_equal User.anonymous, attachment.reload.author | 149 assert_equal User.anonymous, attachment.reload.author |
135 end | 150 end |
136 | 151 |
137 def test_destroy_should_update_comments | 152 def test_destroy_should_update_comments |
138 comment = Comment.create!( | 153 comment = Comment.create!( |
139 :commented => News.create!(:project_id => 1, :author_id => 1, :title => 'foo', :description => 'foo'), | 154 :commented => News.create!(:project_id => 1, :author_id => 1, :title => 'foo', :description => 'foo'), |
140 :author => User.find(2), | 155 :author => User.find(2), |
141 :comments => 'foo' | 156 :comments => 'foo' |
142 ) | 157 ) |
143 | 158 |
144 User.find(2).destroy | 159 User.find(2).destroy |
145 assert_nil User.find_by_id(2) | 160 assert_nil User.find_by_id(2) |
146 assert_equal User.anonymous, comment.reload.author | 161 assert_equal User.anonymous, comment.reload.author |
147 end | 162 end |
148 | 163 |
149 def test_destroy_should_update_issues | 164 def test_destroy_should_update_issues |
150 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') | 165 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') |
151 | 166 |
152 User.find(2).destroy | 167 User.find(2).destroy |
153 assert_nil User.find_by_id(2) | 168 assert_nil User.find_by_id(2) |
154 assert_equal User.anonymous, issue.reload.author | 169 assert_equal User.anonymous, issue.reload.author |
155 end | 170 end |
156 | 171 |
157 def test_destroy_should_unassign_issues | 172 def test_destroy_should_unassign_issues |
158 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) | 173 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) |
159 | 174 |
160 User.find(2).destroy | 175 User.find(2).destroy |
161 assert_nil User.find_by_id(2) | 176 assert_nil User.find_by_id(2) |
162 assert_nil issue.reload.assigned_to | 177 assert_nil issue.reload.assigned_to |
163 end | 178 end |
164 | 179 |
165 def test_destroy_should_update_journals | 180 def test_destroy_should_update_journals |
166 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') | 181 issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') |
167 issue.init_journal(User.find(2), "update") | 182 issue.init_journal(User.find(2), "update") |
168 issue.save! | 183 issue.save! |
169 | 184 |
170 User.find(2).destroy | 185 User.find(2).destroy |
171 assert_nil User.find_by_id(2) | 186 assert_nil User.find_by_id(2) |
172 assert_equal User.anonymous, issue.journals.first.reload.user | 187 assert_equal User.anonymous, issue.journals.first.reload.user |
173 end | 188 end |
174 | 189 |
175 def test_destroy_should_update_journal_details_old_value | 190 def test_destroy_should_update_journal_details_old_value |
176 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) | 191 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) |
177 issue.init_journal(User.find(1), "update") | 192 issue.init_journal(User.find(1), "update") |
178 issue.assigned_to_id = nil | 193 issue.assigned_to_id = nil |
179 assert_difference 'JournalDetail.count' do | 194 assert_difference 'JournalDetail.count' do |
180 issue.save! | 195 issue.save! |
181 end | 196 end |
182 journal_detail = JournalDetail.first(:order => 'id DESC') | 197 journal_detail = JournalDetail.first(:order => 'id DESC') |
183 assert_equal '2', journal_detail.old_value | 198 assert_equal '2', journal_detail.old_value |
184 | 199 |
185 User.find(2).destroy | 200 User.find(2).destroy |
186 assert_nil User.find_by_id(2) | 201 assert_nil User.find_by_id(2) |
187 assert_equal User.anonymous.id.to_s, journal_detail.reload.old_value | 202 assert_equal User.anonymous.id.to_s, journal_detail.reload.old_value |
188 end | 203 end |
189 | 204 |
190 def test_destroy_should_update_journal_details_value | 205 def test_destroy_should_update_journal_details_value |
191 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') | 206 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') |
192 issue.init_journal(User.find(1), "update") | 207 issue.init_journal(User.find(1), "update") |
193 issue.assigned_to_id = 2 | 208 issue.assigned_to_id = 2 |
194 assert_difference 'JournalDetail.count' do | 209 assert_difference 'JournalDetail.count' do |
195 issue.save! | 210 issue.save! |
196 end | 211 end |
197 journal_detail = JournalDetail.first(:order => 'id DESC') | 212 journal_detail = JournalDetail.first(:order => 'id DESC') |
198 assert_equal '2', journal_detail.value | 213 assert_equal '2', journal_detail.value |
199 | 214 |
200 User.find(2).destroy | 215 User.find(2).destroy |
201 assert_nil User.find_by_id(2) | 216 assert_nil User.find_by_id(2) |
202 assert_equal User.anonymous.id.to_s, journal_detail.reload.value | 217 assert_equal User.anonymous.id.to_s, journal_detail.reload.value |
203 end | 218 end |
204 | 219 |
205 def test_destroy_should_update_messages | 220 def test_destroy_should_update_messages |
206 board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board') | 221 board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board') |
207 message = Message.create!(:board_id => board.id, :author_id => 2, :subject => 'foo', :content => 'foo') | 222 message = Message.create!(:board_id => board.id, :author_id => 2, :subject => 'foo', :content => 'foo') |
208 | 223 |
209 User.find(2).destroy | 224 User.find(2).destroy |
210 assert_nil User.find_by_id(2) | 225 assert_nil User.find_by_id(2) |
211 assert_equal User.anonymous, message.reload.author | 226 assert_equal User.anonymous, message.reload.author |
212 end | 227 end |
213 | 228 |
214 def test_destroy_should_update_news | 229 def test_destroy_should_update_news |
215 news = News.create!(:project_id => 1, :author_id => 2, :title => 'foo', :description => 'foo') | 230 news = News.create!(:project_id => 1, :author_id => 2, :title => 'foo', :description => 'foo') |
216 | 231 |
217 User.find(2).destroy | 232 User.find(2).destroy |
218 assert_nil User.find_by_id(2) | 233 assert_nil User.find_by_id(2) |
219 assert_equal User.anonymous, news.reload.author | 234 assert_equal User.anonymous, news.reload.author |
220 end | 235 end |
221 | 236 |
222 def test_destroy_should_delete_private_queries | 237 def test_destroy_should_delete_private_queries |
223 query = Query.new(:name => 'foo', :is_public => false) | 238 query = Query.new(:name => 'foo', :is_public => false) |
224 query.project_id = 1 | 239 query.project_id = 1 |
225 query.user_id = 2 | 240 query.user_id = 2 |
226 query.save! | 241 query.save! |
227 | 242 |
228 User.find(2).destroy | 243 User.find(2).destroy |
229 assert_nil User.find_by_id(2) | 244 assert_nil User.find_by_id(2) |
230 assert_nil Query.find_by_id(query.id) | 245 assert_nil Query.find_by_id(query.id) |
231 end | 246 end |
232 | 247 |
233 def test_destroy_should_update_public_queries | 248 def test_destroy_should_update_public_queries |
234 query = Query.new(:name => 'foo', :is_public => true) | 249 query = Query.new(:name => 'foo', :is_public => true) |
235 query.project_id = 1 | 250 query.project_id = 1 |
236 query.user_id = 2 | 251 query.user_id = 2 |
237 query.save! | 252 query.save! |
238 | 253 |
239 User.find(2).destroy | 254 User.find(2).destroy |
240 assert_nil User.find_by_id(2) | 255 assert_nil User.find_by_id(2) |
241 assert_equal User.anonymous, query.reload.user | 256 assert_equal User.anonymous, query.reload.user |
242 end | 257 end |
243 | 258 |
244 def test_destroy_should_update_time_entries | 259 def test_destroy_should_update_time_entries |
245 entry = TimeEntry.new(:hours => '2', :spent_on => Date.today, :activity => TimeEntryActivity.create!(:name => 'foo')) | 260 entry = TimeEntry.new(:hours => '2', :spent_on => Date.today, :activity => TimeEntryActivity.create!(:name => 'foo')) |
246 entry.project_id = 1 | 261 entry.project_id = 1 |
247 entry.user_id = 2 | 262 entry.user_id = 2 |
248 entry.save! | 263 entry.save! |
249 | 264 |
250 User.find(2).destroy | 265 User.find(2).destroy |
251 assert_nil User.find_by_id(2) | 266 assert_nil User.find_by_id(2) |
252 assert_equal User.anonymous, entry.reload.user | 267 assert_equal User.anonymous, entry.reload.user |
253 end | 268 end |
254 | 269 |
255 def test_destroy_should_delete_tokens | 270 def test_destroy_should_delete_tokens |
256 token = Token.create!(:user_id => 2, :value => 'foo') | 271 token = Token.create!(:user_id => 2, :value => 'foo') |
257 | 272 |
258 User.find(2).destroy | 273 User.find(2).destroy |
259 assert_nil User.find_by_id(2) | 274 assert_nil User.find_by_id(2) |
260 assert_nil Token.find_by_id(token.id) | 275 assert_nil Token.find_by_id(token.id) |
261 end | 276 end |
262 | 277 |
263 def test_destroy_should_delete_watchers | 278 def test_destroy_should_delete_watchers |
264 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') | 279 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') |
265 watcher = Watcher.create!(:user_id => 2, :watchable => issue) | 280 watcher = Watcher.create!(:user_id => 2, :watchable => issue) |
266 | 281 |
267 User.find(2).destroy | 282 User.find(2).destroy |
268 assert_nil User.find_by_id(2) | 283 assert_nil User.find_by_id(2) |
269 assert_nil Watcher.find_by_id(watcher.id) | 284 assert_nil Watcher.find_by_id(watcher.id) |
270 end | 285 end |
271 | 286 |
272 def test_destroy_should_update_wiki_contents | 287 def test_destroy_should_update_wiki_contents |
273 wiki_content = WikiContent.create!( | 288 wiki_content = WikiContent.create!( |
274 :text => 'foo', | 289 :text => 'foo', |
275 :author_id => 2, | 290 :author_id => 2, |
276 :page => WikiPage.create!(:title => 'Foo', :wiki => Wiki.create!(:project_id => 1, :start_page => 'Start')) | 291 :page => WikiPage.create!(:title => 'Foo', :wiki => Wiki.create!(:project_id => 1, :start_page => 'Start')) |
277 ) | 292 ) |
278 wiki_content.text = 'bar' | 293 wiki_content.text = 'bar' |
279 assert_difference 'WikiContent::Version.count' do | 294 assert_difference 'WikiContent::Version.count' do |
280 wiki_content.save! | 295 wiki_content.save! |
281 end | 296 end |
282 | 297 |
283 User.find(2).destroy | 298 User.find(2).destroy |
284 assert_nil User.find_by_id(2) | 299 assert_nil User.find_by_id(2) |
285 assert_equal User.anonymous, wiki_content.reload.author | 300 assert_equal User.anonymous, wiki_content.reload.author |
286 wiki_content.versions.each do |version| | 301 wiki_content.versions.each do |version| |
287 assert_equal User.anonymous, version.reload.author | 302 assert_equal User.anonymous, version.reload.author |
288 end | 303 end |
289 end | 304 end |
290 | 305 |
291 def test_destroy_should_nullify_issue_categories | 306 def test_destroy_should_nullify_issue_categories |
292 category = IssueCategory.create!(:project_id => 1, :assigned_to_id => 2, :name => 'foo') | 307 category = IssueCategory.create!(:project_id => 1, :assigned_to_id => 2, :name => 'foo') |
293 | 308 |
294 User.find(2).destroy | 309 User.find(2).destroy |
295 assert_nil User.find_by_id(2) | 310 assert_nil User.find_by_id(2) |
296 assert_nil category.reload.assigned_to_id | 311 assert_nil category.reload.assigned_to_id |
297 end | 312 end |
298 | 313 |
299 def test_destroy_should_nullify_changesets | 314 def test_destroy_should_nullify_changesets |
300 changeset = Changeset.create!( | 315 changeset = Changeset.create!( |
301 :repository => Repository::Subversion.create!( | 316 :repository => Repository::Subversion.create!( |
302 :project_id => 1, | 317 :project_id => 1, |
303 :url => 'file:///var/svn' | 318 :url => 'file:///var/svn' |
305 :revision => '12', | 320 :revision => '12', |
306 :committed_on => Time.now, | 321 :committed_on => Time.now, |
307 :committer => 'jsmith' | 322 :committer => 'jsmith' |
308 ) | 323 ) |
309 assert_equal 2, changeset.user_id | 324 assert_equal 2, changeset.user_id |
310 | 325 |
311 User.find(2).destroy | 326 User.find(2).destroy |
312 assert_nil User.find_by_id(2) | 327 assert_nil User.find_by_id(2) |
313 assert_nil changeset.reload.user_id | 328 assert_nil changeset.reload.user_id |
314 end | 329 end |
315 | 330 |
316 def test_anonymous_user_should_not_be_destroyable | 331 def test_anonymous_user_should_not_be_destroyable |
317 assert_no_difference 'User.count' do | 332 assert_no_difference 'User.count' do |
318 assert_equal false, User.anonymous.destroy | 333 assert_equal false, User.anonymous.destroy |
319 end | 334 end |
320 end | 335 end |
321 | 336 |
322 def test_validate_login_presence | 337 def test_validate_login_presence |
323 @admin.login = "" | 338 @admin.login = "" |
324 assert !@admin.save | 339 assert !@admin.save |
325 assert_equal 1, @admin.errors.count | 340 assert_equal 1, @admin.errors.count |
326 end | 341 end |
327 | 342 |
328 def test_validate_mail_notification_inclusion | 343 def test_validate_mail_notification_inclusion |
329 u = User.new | 344 u = User.new |
330 u.mail_notification = 'foo' | 345 u.mail_notification = 'foo' |
331 u.save | 346 u.save |
332 assert_not_nil u.errors.on(:mail_notification) | 347 assert_not_nil u.errors[:mail_notification] |
333 end | 348 end |
334 | 349 |
335 context "User#try_to_login" do | 350 context "User#try_to_login" do |
336 should "fall-back to case-insensitive if user login is not found as-typed." do | 351 should "fall-back to case-insensitive if user login is not found as-typed." do |
337 user = User.try_to_login("AdMin", "admin") | 352 user = User.try_to_login("AdMin", "admin") |
338 assert_kind_of User, user | 353 assert_kind_of User, user |
339 assert_equal "admin", user.login | 354 assert_equal "admin", user.login |
340 end | 355 end |
341 | 356 |
342 should "select the exact matching user first" do | 357 should "select the exact matching user first" do |
343 case_sensitive_user = User.generate_with_protected!(:login => 'changed', :password => 'admin', :password_confirmation => 'admin') | 358 case_sensitive_user = User.generate_with_protected!( |
359 :login => 'changed', :password => 'admin', | |
360 :password_confirmation => 'admin') | |
344 # bypass validations to make it appear like existing data | 361 # bypass validations to make it appear like existing data |
345 case_sensitive_user.update_attribute(:login, 'ADMIN') | 362 case_sensitive_user.update_attribute(:login, 'ADMIN') |
346 | 363 |
347 user = User.try_to_login("ADMIN", "admin") | 364 user = User.try_to_login("ADMIN", "admin") |
348 assert_kind_of User, user | 365 assert_kind_of User, user |
355 user = User.try_to_login("admin", "admin") | 372 user = User.try_to_login("admin", "admin") |
356 assert_kind_of User, user | 373 assert_kind_of User, user |
357 assert_equal "admin", user.login | 374 assert_equal "admin", user.login |
358 user.password = "hello" | 375 user.password = "hello" |
359 assert user.save | 376 assert user.save |
360 | 377 |
361 user = User.try_to_login("admin", "hello") | 378 user = User.try_to_login("admin", "hello") |
362 assert_kind_of User, user | 379 assert_kind_of User, user |
363 assert_equal "admin", user.login | 380 assert_equal "admin", user.login |
364 end | 381 end |
365 | 382 |
383 def test_validate_password_length | |
384 with_settings :password_min_length => '100' do | |
385 user = User.new(:firstname => "new100", :lastname => "user100", :mail => "newuser100@somenet.foo") | |
386 user.login = "newuser100" | |
387 user.password, user.password_confirmation = "password100", "password100" | |
388 assert !user.save | |
389 assert_equal 1, user.errors.count | |
390 end | |
391 end | |
392 | |
366 def test_name_format | 393 def test_name_format |
367 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) | 394 assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) |
368 Setting.user_format = :firstname_lastname | 395 Setting.user_format = :firstname_lastname |
369 assert_equal 'John Smith', @jsmith.reload.name | 396 assert_equal 'John Smith', @jsmith.reload.name |
370 Setting.user_format = :username | 397 Setting.user_format = :username |
371 assert_equal 'jsmith', @jsmith.reload.name | 398 assert_equal 'jsmith', @jsmith.reload.name |
372 end | 399 end |
373 | 400 |
401 def test_fields_for_order_statement_should_return_fields_according_user_format_setting | |
402 with_settings :user_format => 'lastname_coma_firstname' do | |
403 assert_equal ['users.lastname', 'users.firstname', 'users.id'], User.fields_for_order_statement | |
404 end | |
405 end | |
406 | |
407 def test_fields_for_order_statement_width_table_name_should_prepend_table_name | |
408 with_settings :user_format => 'lastname_firstname' do | |
409 assert_equal ['authors.lastname', 'authors.firstname', 'authors.id'], User.fields_for_order_statement('authors') | |
410 end | |
411 end | |
412 | |
413 def test_fields_for_order_statement_with_blank_format_should_return_default | |
414 with_settings :user_format => '' do | |
415 assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement | |
416 end | |
417 end | |
418 | |
419 def test_fields_for_order_statement_with_invalid_format_should_return_default | |
420 with_settings :user_format => 'foo' do | |
421 assert_equal ['users.firstname', 'users.lastname', 'users.id'], User.fields_for_order_statement | |
422 end | |
423 end | |
424 | |
374 def test_lock | 425 def test_lock |
375 user = User.try_to_login("jsmith", "jsmith") | 426 user = User.try_to_login("jsmith", "jsmith") |
376 assert_equal @jsmith, user | 427 assert_equal @jsmith, user |
377 | 428 |
378 @jsmith.status = User::STATUS_LOCKED | 429 @jsmith.status = User::STATUS_LOCKED |
379 assert @jsmith.save | 430 assert @jsmith.save |
380 | 431 |
381 user = User.try_to_login("jsmith", "jsmith") | 432 user = User.try_to_login("jsmith", "jsmith") |
382 assert_equal nil, user | 433 assert_equal nil, user |
383 end | 434 end |
384 | 435 |
385 context ".try_to_login" do | 436 context ".try_to_login" do |
386 context "with good credentials" do | 437 context "with good credentials" do |
387 should "return the user" do | 438 should "return the user" do |
388 user = User.try_to_login("admin", "admin") | 439 user = User.try_to_login("admin", "admin") |
389 assert_kind_of User, user | 440 assert_kind_of User, user |
390 assert_equal "admin", user.login | 441 assert_equal "admin", user.login |
391 end | 442 end |
392 end | 443 end |
393 | 444 |
394 context "with wrong credentials" do | 445 context "with wrong credentials" do |
395 should "return nil" do | 446 should "return nil" do |
396 assert_nil User.try_to_login("admin", "foo") | 447 assert_nil User.try_to_login("admin", "foo") |
397 end | 448 end |
398 end | 449 end |
399 end | 450 end |
400 | 451 |
401 if ldap_configured? | 452 if ldap_configured? |
402 context "#try_to_login using LDAP" do | 453 context "#try_to_login using LDAP" do |
403 context "with failed connection to the LDAP server" do | 454 context "with failed connection to the LDAP server" do |
404 should "return nil" do | 455 should "return nil" do |
405 @auth_source = AuthSourceLdap.find(1) | 456 @auth_source = AuthSourceLdap.find(1) |
406 AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') | 457 AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') |
407 | 458 |
408 assert_equal nil, User.try_to_login('edavis', 'wrong') | 459 assert_equal nil, User.try_to_login('edavis', 'wrong') |
409 end | 460 end |
410 end | 461 end |
411 | 462 |
412 context "with an unsuccessful authentication" do | 463 context "with an unsuccessful authentication" do |
413 should "return nil" do | 464 should "return nil" do |
414 assert_equal nil, User.try_to_login('edavis', 'wrong') | 465 assert_equal nil, User.try_to_login('edavis', 'wrong') |
415 end | 466 end |
416 end | 467 end |
417 | 468 |
418 context "on the fly registration" do | 469 context "on the fly registration" do |
419 setup do | 470 setup do |
420 @auth_source = AuthSourceLdap.find(1) | 471 @auth_source = AuthSourceLdap.find(1) |
421 end | 472 end |
422 | 473 |
425 assert_difference('User.count') do | 476 assert_difference('User.count') do |
426 user = User.try_to_login('edavis', '123456') | 477 user = User.try_to_login('edavis', '123456') |
427 assert !user.admin? | 478 assert !user.admin? |
428 end | 479 end |
429 end | 480 end |
430 | 481 |
431 should "retrieve existing user" do | 482 should "retrieve existing user" do |
432 user = User.try_to_login('edavis', '123456') | 483 user = User.try_to_login('edavis', '123456') |
433 user.admin = true | 484 user.admin = true |
434 user.save! | 485 user.save! |
435 | 486 |
436 assert_no_difference('User.count') do | 487 assert_no_difference('User.count') do |
437 user = User.try_to_login('edavis', '123456') | 488 user = User.try_to_login('edavis', '123456') |
438 assert user.admin? | 489 assert user.admin? |
439 end | 490 end |
440 end | 491 end |
443 end | 494 end |
444 | 495 |
445 else | 496 else |
446 puts "Skipping LDAP tests." | 497 puts "Skipping LDAP tests." |
447 end | 498 end |
448 | 499 |
449 def test_create_anonymous | 500 def test_create_anonymous |
450 AnonymousUser.delete_all | 501 AnonymousUser.delete_all |
451 anon = User.anonymous | 502 anon = User.anonymous |
452 assert !anon.new_record? | 503 assert !anon.new_record? |
453 assert_kind_of AnonymousUser, anon | 504 assert_kind_of AnonymousUser, anon |
454 end | 505 end |
455 | 506 |
507 def test_ensure_single_anonymous_user | |
508 AnonymousUser.delete_all | |
509 anon1 = User.anonymous | |
510 assert !anon1.new_record? | |
511 assert_kind_of AnonymousUser, anon1 | |
512 anon2 = AnonymousUser.create( | |
513 :lastname => 'Anonymous', :firstname => '', | |
514 :mail => '', :login => '', :status => 0) | |
515 assert_equal 1, anon2.errors.count | |
516 end | |
517 | |
456 should_have_one :rss_token | 518 should_have_one :rss_token |
457 | 519 |
458 def test_rss_key | 520 def test_rss_key |
459 assert_nil @jsmith.rss_token | 521 assert_nil @jsmith.rss_token |
460 key = @jsmith.rss_key | 522 key = @jsmith.rss_key |
461 assert_equal 40, key.length | 523 assert_equal 40, key.length |
462 | 524 |
463 @jsmith.reload | 525 @jsmith.reload |
464 assert_equal key, @jsmith.rss_key | 526 assert_equal key, @jsmith.rss_key |
465 end | 527 end |
466 | 528 |
467 | 529 |
468 should_have_one :api_token | 530 should_have_one :api_token |
469 | 531 |
470 context "User#api_key" do | 532 context "User#api_key" do |
471 should "generate a new one if the user doesn't have one" do | 533 should "generate a new one if the user doesn't have one" do |
472 user = User.generate_with_protected!(:api_token => nil) | 534 user = User.generate_with_protected!(:api_token => nil) |
481 should "return the existing api token value" do | 543 should "return the existing api token value" do |
482 user = User.generate_with_protected! | 544 user = User.generate_with_protected! |
483 token = Token.generate!(:action => 'api') | 545 token = Token.generate!(:action => 'api') |
484 user.api_token = token | 546 user.api_token = token |
485 assert user.save | 547 assert user.save |
486 | 548 |
487 assert_equal token.value, user.api_key | 549 assert_equal token.value, user.api_key |
488 end | 550 end |
489 end | 551 end |
490 | 552 |
491 context "User#find_by_api_key" do | 553 context "User#find_by_api_key" do |
505 should "return the user if the key is found for an active user" do | 567 should "return the user if the key is found for an active user" do |
506 user = User.generate_with_protected!(:status => User::STATUS_ACTIVE) | 568 user = User.generate_with_protected!(:status => User::STATUS_ACTIVE) |
507 token = Token.generate!(:action => 'api') | 569 token = Token.generate!(:action => 'api') |
508 user.api_token = token | 570 user.api_token = token |
509 user.save | 571 user.save |
510 | 572 |
511 assert_equal user, User.find_by_api_key(token.value) | 573 assert_equal user, User.find_by_api_key(token.value) |
512 end | 574 end |
513 end | 575 end |
514 | 576 |
515 def test_roles_for_project | 577 def test_roles_for_project |
516 # user with a role | 578 # user with a role |
517 roles = @jsmith.roles_for_project(Project.find(1)) | 579 roles = @jsmith.roles_for_project(Project.find(1)) |
518 assert_kind_of Role, roles.first | 580 assert_kind_of Role, roles.first |
519 assert_equal "Manager", roles.first.name | 581 assert_equal "Manager", roles.first.name |
520 | 582 |
521 # user with no role | 583 # user with no role |
522 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} | 584 assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} |
523 end | 585 end |
524 | 586 |
525 def test_projects_by_role_for_user_with_role | 587 def test_projects_by_role_for_user_with_role |
526 user = User.find(2) | 588 user = User.find(2) |
527 assert_kind_of Hash, user.projects_by_role | 589 assert_kind_of Hash, user.projects_by_role |
528 assert_equal 2, user.projects_by_role.size | 590 assert_equal 2, user.projects_by_role.size |
529 assert_equal [1,5], user.projects_by_role[Role.find(1)].collect(&:id).sort | 591 assert_equal [1,5], user.projects_by_role[Role.find(1)].collect(&:id).sort |
530 assert_equal [2], user.projects_by_role[Role.find(2)].collect(&:id).sort | 592 assert_equal [2], user.projects_by_role[Role.find(2)].collect(&:id).sort |
531 end | 593 end |
532 | 594 |
533 def test_projects_by_role_for_user_with_no_role | 595 def test_projects_by_role_for_user_with_no_role |
534 user = User.generate! | 596 user = User.generate! |
535 assert_equal({}, user.projects_by_role) | 597 assert_equal({}, user.projects_by_role) |
536 end | 598 end |
537 | 599 |
538 def test_projects_by_role_for_anonymous | 600 def test_projects_by_role_for_anonymous |
539 assert_equal({}, User.anonymous.projects_by_role) | 601 assert_equal({}, User.anonymous.projects_by_role) |
540 end | 602 end |
541 | 603 |
542 def test_valid_notification_options | 604 def test_valid_notification_options |
543 # without memberships | 605 # without memberships |
544 assert_equal 5, User.find(7).valid_notification_options.size | 606 assert_equal 5, User.find(7).valid_notification_options.size |
545 # with memberships | 607 # with memberships |
546 assert_equal 6, User.find(2).valid_notification_options.size | 608 assert_equal 6, User.find(2).valid_notification_options.size |
547 end | 609 end |
548 | 610 |
549 def test_valid_notification_options_class_method | 611 def test_valid_notification_options_class_method |
550 assert_equal 5, User.valid_notification_options.size | 612 assert_equal 5, User.valid_notification_options.size |
551 assert_equal 5, User.valid_notification_options(User.find(7)).size | 613 assert_equal 5, User.valid_notification_options(User.find(7)).size |
552 assert_equal 6, User.valid_notification_options(User.find(2)).size | 614 assert_equal 6, User.valid_notification_options(User.find(2)).size |
553 end | 615 end |
554 | 616 |
555 def test_mail_notification_all | 617 def test_mail_notification_all |
556 @jsmith.mail_notification = 'all' | 618 @jsmith.mail_notification = 'all' |
557 @jsmith.notified_project_ids = [] | 619 @jsmith.notified_project_ids = [] |
558 @jsmith.save | 620 @jsmith.save |
559 @jsmith.reload | 621 @jsmith.reload |
560 assert @jsmith.projects.first.recipients.include?(@jsmith.mail) | 622 assert @jsmith.projects.first.recipients.include?(@jsmith.mail) |
561 end | 623 end |
562 | 624 |
563 def test_mail_notification_selected | 625 def test_mail_notification_selected |
564 @jsmith.mail_notification = 'selected' | 626 @jsmith.mail_notification = 'selected' |
565 @jsmith.notified_project_ids = [1] | 627 @jsmith.notified_project_ids = [1] |
566 @jsmith.save | 628 @jsmith.save |
567 @jsmith.reload | 629 @jsmith.reload |
568 assert Project.find(1).recipients.include?(@jsmith.mail) | 630 assert Project.find(1).recipients.include?(@jsmith.mail) |
569 end | 631 end |
570 | 632 |
571 def test_mail_notification_only_my_events | 633 def test_mail_notification_only_my_events |
572 @jsmith.mail_notification = 'only_my_events' | 634 @jsmith.mail_notification = 'only_my_events' |
573 @jsmith.notified_project_ids = [] | 635 @jsmith.notified_project_ids = [] |
574 @jsmith.save | 636 @jsmith.save |
575 @jsmith.reload | 637 @jsmith.reload |
576 assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) | 638 assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) |
577 end | 639 end |
578 | 640 |
579 def test_comments_sorting_preference | 641 def test_comments_sorting_preference |
580 assert !@jsmith.wants_comments_in_reverse_order? | 642 assert !@jsmith.wants_comments_in_reverse_order? |
581 @jsmith.pref.comments_sorting = 'asc' | 643 @jsmith.pref.comments_sorting = 'asc' |
582 assert !@jsmith.wants_comments_in_reverse_order? | 644 assert !@jsmith.wants_comments_in_reverse_order? |
583 @jsmith.pref.comments_sorting = 'desc' | 645 @jsmith.pref.comments_sorting = 'desc' |
584 assert @jsmith.wants_comments_in_reverse_order? | 646 assert @jsmith.wants_comments_in_reverse_order? |
585 end | 647 end |
586 | 648 |
587 def test_find_by_mail_should_be_case_insensitive | 649 def test_find_by_mail_should_be_case_insensitive |
588 u = User.find_by_mail('JSmith@somenet.foo') | 650 u = User.find_by_mail('JSmith@somenet.foo') |
589 assert_not_nil u | 651 assert_not_nil u |
590 assert_equal 'jsmith@somenet.foo', u.mail | 652 assert_equal 'jsmith@somenet.foo', u.mail |
591 end | 653 end |
592 | 654 |
593 def test_random_password | 655 def test_random_password |
594 u = User.new | 656 u = User.new |
595 u.random_password | 657 u.random_password |
596 assert !u.password.blank? | 658 assert !u.password.blank? |
597 assert !u.password_confirmation.blank? | 659 assert !u.password_confirmation.blank? |
603 assert user.change_password_allowed? | 665 assert user.change_password_allowed? |
604 end | 666 end |
605 | 667 |
606 should "delegate to the auth source" do | 668 should "delegate to the auth source" do |
607 user = User.generate_with_protected! | 669 user = User.generate_with_protected! |
608 | 670 |
609 allowed_auth_source = AuthSource.generate! | 671 allowed_auth_source = AuthSource.generate! |
610 def allowed_auth_source.allow_password_changes?; true; end | 672 def allowed_auth_source.allow_password_changes?; true; end |
611 | 673 |
612 denied_auth_source = AuthSource.generate! | 674 denied_auth_source = AuthSource.generate! |
613 def denied_auth_source.allow_password_changes?; false; end | 675 def denied_auth_source.allow_password_changes?; false; end |
620 user.auth_source = denied_auth_source | 682 user.auth_source = denied_auth_source |
621 assert !user.change_password_allowed?, "User allowed to change password, though auth source does not" | 683 assert !user.change_password_allowed?, "User allowed to change password, though auth source does not" |
622 end | 684 end |
623 | 685 |
624 end | 686 end |
625 | 687 |
626 context "#allowed_to?" do | 688 context "#allowed_to?" do |
627 context "with a unique project" do | 689 context "with a unique project" do |
628 should "return false if project is archived" do | 690 should "return false if project is archived" do |
629 project = Project.find(1) | 691 project = Project.find(1) |
630 Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED) | 692 Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED) |
631 assert ! @admin.allowed_to?(:view_issues, Project.find(1)) | 693 assert ! @admin.allowed_to?(:view_issues, Project.find(1)) |
632 end | 694 end |
633 | 695 |
634 should "return false if related module is disabled" do | 696 should "return false if related module is disabled" do |
635 project = Project.find(1) | 697 project = Project.find(1) |
636 project.enabled_module_names = ["issue_tracking"] | 698 project.enabled_module_names = ["issue_tracking"] |
637 assert @admin.allowed_to?(:add_issues, project) | 699 assert @admin.allowed_to?(:add_issues, project) |
638 assert ! @admin.allowed_to?(:view_wiki_pages, project) | 700 assert ! @admin.allowed_to?(:view_wiki_pages, project) |
639 end | 701 end |
640 | 702 |
641 should "authorize nearly everything for admin users" do | 703 should "authorize nearly everything for admin users" do |
642 project = Project.find(1) | 704 project = Project.find(1) |
643 assert ! @admin.member_of?(project) | 705 assert ! @admin.member_of?(project) |
644 %w(edit_issues delete_issues manage_news manage_documents manage_wiki).each do |p| | 706 %w(edit_issues delete_issues manage_news manage_documents manage_wiki).each do |p| |
645 assert @admin.allowed_to?(p.to_sym, project) | 707 assert @admin.allowed_to?(p.to_sym, project) |
646 end | 708 end |
647 end | 709 end |
648 | 710 |
649 should "authorize normal users depending on their roles" do | 711 should "authorize normal users depending on their roles" do |
650 project = Project.find(1) | 712 project = Project.find(1) |
651 assert @jsmith.allowed_to?(:delete_messages, project) #Manager | 713 assert @jsmith.allowed_to?(:delete_messages, project) #Manager |
652 assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper | 714 assert ! @dlopper.allowed_to?(:delete_messages, project) #Developper |
653 end | 715 end |
655 | 717 |
656 context "with multiple projects" do | 718 context "with multiple projects" do |
657 should "return false if array is empty" do | 719 should "return false if array is empty" do |
658 assert ! @admin.allowed_to?(:view_project, []) | 720 assert ! @admin.allowed_to?(:view_project, []) |
659 end | 721 end |
660 | 722 |
661 should "return true only if user has permission on all these projects" do | 723 should "return true only if user has permission on all these projects" do |
662 assert @admin.allowed_to?(:view_project, Project.all) | 724 assert @admin.allowed_to?(:view_project, Project.all) |
663 assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) | 725 assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) |
664 assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere | 726 assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere |
665 assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers | 727 assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers |
666 end | 728 end |
667 | 729 |
668 should "behave correctly with arrays of 1 project" do | 730 should "behave correctly with arrays of 1 project" do |
669 assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) | 731 assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) |
670 end | 732 end |
671 end | 733 end |
672 | 734 |
673 context "with options[:global]" do | 735 context "with options[:global]" do |
674 should "authorize if user has at least one role that has this permission" do | 736 should "authorize if user has at least one role that has this permission" do |
675 @dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere | 737 @dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere |
676 @anonymous = User.find(6) | 738 @anonymous = User.find(6) |
677 assert @jsmith.allowed_to?(:delete_issue_watchers, nil, :global => true) | 739 assert @jsmith.allowed_to?(:delete_issue_watchers, nil, :global => true) |
680 assert ! @anonymous.allowed_to?(:add_issues, nil, :global => true) | 742 assert ! @anonymous.allowed_to?(:add_issues, nil, :global => true) |
681 assert @anonymous.allowed_to?(:view_issues, nil, :global => true) | 743 assert @anonymous.allowed_to?(:view_issues, nil, :global => true) |
682 end | 744 end |
683 end | 745 end |
684 end | 746 end |
685 | 747 |
686 context "User#notify_about?" do | 748 context "User#notify_about?" do |
687 context "Issues" do | 749 context "Issues" do |
688 setup do | 750 setup do |
689 @project = Project.find(1) | 751 @project = Project.find(1) |
690 @author = User.generate_with_protected! | 752 @author = User.generate_with_protected! |
694 | 756 |
695 should "be true for a user with :all" do | 757 should "be true for a user with :all" do |
696 @author.update_attribute(:mail_notification, 'all') | 758 @author.update_attribute(:mail_notification, 'all') |
697 assert @author.notify_about?(@issue) | 759 assert @author.notify_about?(@issue) |
698 end | 760 end |
699 | 761 |
700 should "be false for a user with :none" do | 762 should "be false for a user with :none" do |
701 @author.update_attribute(:mail_notification, 'none') | 763 @author.update_attribute(:mail_notification, 'none') |
702 assert ! @author.notify_about?(@issue) | 764 assert ! @author.notify_about?(@issue) |
703 end | 765 end |
704 | 766 |
705 should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do | 767 should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do |
706 @user = User.generate_with_protected!(:mail_notification => 'only_my_events') | 768 @user = User.generate_with_protected!(:mail_notification => 'only_my_events') |
707 Member.create!(:user => @user, :project => @project, :role_ids => [1]) | 769 Member.create!(:user => @user, :project => @project, :role_ids => [1]) |
708 assert ! @user.notify_about?(@issue) | 770 assert ! @user.notify_about?(@issue) |
709 end | 771 end |
710 | 772 |
711 should "be true for a user with :only_my_events and is the author" do | 773 should "be true for a user with :only_my_events and is the author" do |
712 @author.update_attribute(:mail_notification, 'only_my_events') | 774 @author.update_attribute(:mail_notification, 'only_my_events') |
713 assert @author.notify_about?(@issue) | 775 assert @author.notify_about?(@issue) |
714 end | 776 end |
715 | 777 |
716 should "be true for a user with :only_my_events and is the assignee" do | 778 should "be true for a user with :only_my_events and is the assignee" do |
717 @assignee.update_attribute(:mail_notification, 'only_my_events') | 779 @assignee.update_attribute(:mail_notification, 'only_my_events') |
718 assert @assignee.notify_about?(@issue) | 780 assert @assignee.notify_about?(@issue) |
719 end | 781 end |
720 | 782 |
721 should "be true for a user with :only_assigned and is the assignee" do | 783 should "be true for a user with :only_assigned and is the assignee" do |
722 @assignee.update_attribute(:mail_notification, 'only_assigned') | 784 @assignee.update_attribute(:mail_notification, 'only_assigned') |
723 assert @assignee.notify_about?(@issue) | 785 assert @assignee.notify_about?(@issue) |
724 end | 786 end |
725 | 787 |
726 should "be false for a user with :only_assigned and is not the assignee" do | 788 should "be false for a user with :only_assigned and is not the assignee" do |
727 @author.update_attribute(:mail_notification, 'only_assigned') | 789 @author.update_attribute(:mail_notification, 'only_assigned') |
728 assert ! @author.notify_about?(@issue) | 790 assert ! @author.notify_about?(@issue) |
729 end | 791 end |
730 | 792 |
731 should "be true for a user with :only_owner and is the author" do | 793 should "be true for a user with :only_owner and is the author" do |
732 @author.update_attribute(:mail_notification, 'only_owner') | 794 @author.update_attribute(:mail_notification, 'only_owner') |
733 assert @author.notify_about?(@issue) | 795 assert @author.notify_about?(@issue) |
734 end | 796 end |
735 | 797 |
736 should "be false for a user with :only_owner and is not the author" do | 798 should "be false for a user with :only_owner and is not the author" do |
737 @assignee.update_attribute(:mail_notification, 'only_owner') | 799 @assignee.update_attribute(:mail_notification, 'only_owner') |
738 assert ! @assignee.notify_about?(@issue) | 800 assert ! @assignee.notify_about?(@issue) |
739 end | 801 end |
740 | 802 |
741 should "be true for a user with :selected and is the author" do | 803 should "be true for a user with :selected and is the author" do |
742 @author.update_attribute(:mail_notification, 'selected') | 804 @author.update_attribute(:mail_notification, 'selected') |
743 assert @author.notify_about?(@issue) | 805 assert @author.notify_about?(@issue) |
744 end | 806 end |
745 | 807 |
746 should "be true for a user with :selected and is the assignee" do | 808 should "be true for a user with :selected and is the assignee" do |
747 @assignee.update_attribute(:mail_notification, 'selected') | 809 @assignee.update_attribute(:mail_notification, 'selected') |
748 assert @assignee.notify_about?(@issue) | 810 assert @assignee.notify_about?(@issue) |
749 end | 811 end |
750 | 812 |
751 should "be false for a user with :selected and is not the author or assignee" do | 813 should "be false for a user with :selected and is not the author or assignee" do |
752 @user = User.generate_with_protected!(:mail_notification => 'selected') | 814 @user = User.generate_with_protected!(:mail_notification => 'selected') |
753 Member.create!(:user => @user, :project => @project, :role_ids => [1]) | 815 Member.create!(:user => @user, :project => @project, :role_ids => [1]) |
754 assert ! @user.notify_about?(@issue) | 816 assert ! @user.notify_about?(@issue) |
755 end | 817 end |
764 # Restore a user with an unsalted password | 826 # Restore a user with an unsalted password |
765 user = User.find(1) | 827 user = User.find(1) |
766 user.salt = nil | 828 user.salt = nil |
767 user.hashed_password = User.hash_password("unsalted") | 829 user.hashed_password = User.hash_password("unsalted") |
768 user.save! | 830 user.save! |
769 | 831 |
770 User.salt_unsalted_passwords! | 832 User.salt_unsalted_passwords! |
771 | 833 |
772 user.reload | 834 user.reload |
773 # Salt added | 835 # Salt added |
774 assert !user.salt.blank? | 836 assert !user.salt.blank? |
775 # Password still valid | 837 # Password still valid |
776 assert user.check_password?("unsalted") | 838 assert user.check_password?("unsalted") |
777 assert_equal user, User.try_to_login(user.login, "unsalted") | 839 assert_equal user, User.try_to_login(user.login, "unsalted") |
778 end | 840 end |
779 | 841 |
780 if Object.const_defined?(:OpenID) | 842 if Object.const_defined?(:OpenID) |
781 | 843 |
782 def test_setting_identity_url | 844 def test_setting_identity_url |
783 normalized_open_id_url = 'http://example.com/' | 845 normalized_open_id_url = 'http://example.com/' |
784 u = User.new( :identity_url => 'http://example.com/' ) | 846 u = User.new( :identity_url => 'http://example.com/' ) |
785 assert_equal normalized_open_id_url, u.identity_url | 847 assert_equal normalized_open_id_url, u.identity_url |
786 end | 848 end |
794 def test_setting_identity_url_without_protocol | 856 def test_setting_identity_url_without_protocol |
795 normalized_open_id_url = 'http://example.com/' | 857 normalized_open_id_url = 'http://example.com/' |
796 u = User.new( :identity_url => 'example.com' ) | 858 u = User.new( :identity_url => 'example.com' ) |
797 assert_equal normalized_open_id_url, u.identity_url | 859 assert_equal normalized_open_id_url, u.identity_url |
798 end | 860 end |
799 | 861 |
800 def test_setting_blank_identity_url | 862 def test_setting_blank_identity_url |
801 u = User.new( :identity_url => 'example.com' ) | 863 u = User.new( :identity_url => 'example.com' ) |
802 u.identity_url = '' | 864 u.identity_url = '' |
803 assert u.identity_url.blank? | 865 assert u.identity_url.blank? |
804 end | 866 end |
805 | 867 |
806 def test_setting_invalid_identity_url | 868 def test_setting_invalid_identity_url |
807 u = User.new( :identity_url => 'this is not an openid url' ) | 869 u = User.new( :identity_url => 'this is not an openid url' ) |
808 assert u.identity_url.blank? | 870 assert u.identity_url.blank? |
809 end | 871 end |
810 | 872 |
811 else | 873 else |
812 puts "Skipping openid tests." | 874 puts "Skipping openid tests." |
813 end | 875 end |
814 | 876 |
815 end | 877 end |