@@ -5,12 +5,12 | |||||
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. | |
@@ -31,17 +31,17 class UserTest < ActiveSupport::TestCase | |||||
31 | User.generate_with_protected!(:firstname => 'Testing connection') |
|
31 | User.generate_with_protected!(:firstname => 'Testing connection') | |
32 | assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'}) |
|
32 | assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'}) | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_truth |
|
35 | def test_truth | |
36 | assert_kind_of User, @jsmith |
|
36 | assert_kind_of User, @jsmith | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_mail_should_be_stripped |
|
39 | def test_mail_should_be_stripped | |
40 | u = User.new |
|
40 | u = User.new | |
41 | u.mail = " foo@bar.com " |
|
41 | u.mail = " foo@bar.com " | |
42 | assert_equal "foo@bar.com", u.mail |
|
42 | assert_equal "foo@bar.com", u.mail | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_mail_validation |
|
45 | def test_mail_validation | |
46 | u = User.new |
|
46 | u = User.new | |
47 | u.mail = '' |
|
47 | u.mail = '' | |
@@ -51,13 +51,13 class UserTest < ActiveSupport::TestCase | |||||
51 |
|
51 | |||
52 | def test_create |
|
52 | def test_create | |
53 | user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
|
53 | user = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | |
54 |
|
54 | |||
55 | user.login = "jsmith" |
|
55 | user.login = "jsmith" | |
56 | user.password, user.password_confirmation = "password", "password" |
|
56 | user.password, user.password_confirmation = "password", "password" | |
57 | # login uniqueness |
|
57 | # login uniqueness | |
58 | assert !user.save |
|
58 | assert !user.save | |
59 | assert_equal 1, user.errors.count |
|
59 | assert_equal 1, user.errors.count | |
60 |
|
60 | |||
61 | user.login = "newuser" |
|
61 | user.login = "newuser" | |
62 | user.password, user.password_confirmation = "passwd", "password" |
|
62 | user.password, user.password_confirmation = "passwd", "password" | |
63 | # password confirmation |
|
63 | # password confirmation | |
@@ -79,14 +79,14 class UserTest < ActiveSupport::TestCase | |||||
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | context "User.login" do |
|
83 | context "User.login" do | |
84 | should "be case-insensitive." do |
|
84 | should "be case-insensitive." do | |
85 | u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") |
|
85 | u = User.new(:firstname => "new", :lastname => "user", :mail => "newuser@somenet.foo") | |
86 | u.login = 'newuser' |
|
86 | u.login = 'newuser' | |
87 | u.password, u.password_confirmation = "password", "password" |
|
87 | u.password, u.password_confirmation = "password", "password" | |
88 | assert u.save |
|
88 | assert u.save | |
89 |
|
89 | |||
90 | u = User.new(:firstname => "Similar", :lastname => "User", :mail => "similaruser@somenet.foo") |
|
90 | u = User.new(:firstname => "Similar", :lastname => "User", :mail => "similaruser@somenet.foo") | |
91 | u.login = 'NewUser' |
|
91 | u.login = 'NewUser' | |
92 | u.password, u.password_confirmation = "password", "password" |
|
92 | u.password, u.password_confirmation = "password", "password" | |
@@ -100,7 +100,7 class UserTest < ActiveSupport::TestCase | |||||
100 | u.login = 'newuser1' |
|
100 | u.login = 'newuser1' | |
101 | u.password, u.password_confirmation = "password", "password" |
|
101 | u.password, u.password_confirmation = "password", "password" | |
102 | assert u.save |
|
102 | assert u.save | |
103 |
|
103 | |||
104 | u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo") |
|
104 | u = User.new(:firstname => "new", :lastname => "user", :mail => "newUser@Somenet.foo") | |
105 | u.login = 'newuser2' |
|
105 | u.login = 'newuser2' | |
106 | u.password, u.password_confirmation = "password", "password" |
|
106 | u.password, u.password_confirmation = "password", "password" | |
@@ -115,70 +115,70 class UserTest < ActiveSupport::TestCase | |||||
115 | @admin.reload |
|
115 | @admin.reload | |
116 | assert_equal "john", @admin.login |
|
116 | assert_equal "john", @admin.login | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_destroy_should_delete_members_and_roles |
|
119 | def test_destroy_should_delete_members_and_roles | |
120 | members = Member.find_all_by_user_id(2) |
|
120 | members = Member.find_all_by_user_id(2) | |
121 | ms = members.size |
|
121 | ms = members.size | |
122 | rs = members.collect(&:roles).flatten.size |
|
122 | rs = members.collect(&:roles).flatten.size | |
123 |
|
123 | |||
124 | assert_difference 'Member.count', - ms do |
|
124 | assert_difference 'Member.count', - ms do | |
125 | assert_difference 'MemberRole.count', - rs do |
|
125 | assert_difference 'MemberRole.count', - rs do | |
126 | User.find(2).destroy |
|
126 | User.find(2).destroy | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | assert_nil User.find_by_id(2) |
|
130 | assert_nil User.find_by_id(2) | |
131 | assert Member.find_all_by_user_id(2).empty? |
|
131 | assert Member.find_all_by_user_id(2).empty? | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_destroy_should_update_attachments |
|
134 | def test_destroy_should_update_attachments | |
135 | attachment = Attachment.create!(:container => Project.find(1), |
|
135 | attachment = Attachment.create!(:container => Project.find(1), | |
136 | :file => uploaded_test_file("testfile.txt", "text/plain"), |
|
136 | :file => uploaded_test_file("testfile.txt", "text/plain"), | |
137 | :author_id => 2) |
|
137 | :author_id => 2) | |
138 |
|
138 | |||
139 | User.find(2).destroy |
|
139 | User.find(2).destroy | |
140 | assert_nil User.find_by_id(2) |
|
140 | assert_nil User.find_by_id(2) | |
141 | assert_equal User.anonymous, attachment.reload.author |
|
141 | assert_equal User.anonymous, attachment.reload.author | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def test_destroy_should_update_comments |
|
144 | def test_destroy_should_update_comments | |
145 | comment = Comment.create!( |
|
145 | comment = Comment.create!( | |
146 | :commented => News.create!(:project_id => 1, :author_id => 1, :title => 'foo', :description => 'foo'), |
|
146 | :commented => News.create!(:project_id => 1, :author_id => 1, :title => 'foo', :description => 'foo'), | |
147 | :author => User.find(2), |
|
147 | :author => User.find(2), | |
148 | :comments => 'foo' |
|
148 | :comments => 'foo' | |
149 | ) |
|
149 | ) | |
150 |
|
150 | |||
151 | User.find(2).destroy |
|
151 | User.find(2).destroy | |
152 | assert_nil User.find_by_id(2) |
|
152 | assert_nil User.find_by_id(2) | |
153 | assert_equal User.anonymous, comment.reload.author |
|
153 | assert_equal User.anonymous, comment.reload.author | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def test_destroy_should_update_issues |
|
156 | def test_destroy_should_update_issues | |
157 | issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') |
|
157 | issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') | |
158 |
|
158 | |||
159 | User.find(2).destroy |
|
159 | User.find(2).destroy | |
160 | assert_nil User.find_by_id(2) |
|
160 | assert_nil User.find_by_id(2) | |
161 | assert_equal User.anonymous, issue.reload.author |
|
161 | assert_equal User.anonymous, issue.reload.author | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def test_destroy_should_unassign_issues |
|
164 | def test_destroy_should_unassign_issues | |
165 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) |
|
165 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) | |
166 |
|
166 | |||
167 | User.find(2).destroy |
|
167 | User.find(2).destroy | |
168 | assert_nil User.find_by_id(2) |
|
168 | assert_nil User.find_by_id(2) | |
169 | assert_nil issue.reload.assigned_to |
|
169 | assert_nil issue.reload.assigned_to | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_destroy_should_update_journals |
|
172 | def test_destroy_should_update_journals | |
173 | issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') |
|
173 | issue = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'foo') | |
174 | issue.init_journal(User.find(2), "update") |
|
174 | issue.init_journal(User.find(2), "update") | |
175 | issue.save! |
|
175 | issue.save! | |
176 |
|
176 | |||
177 | User.find(2).destroy |
|
177 | User.find(2).destroy | |
178 | assert_nil User.find_by_id(2) |
|
178 | assert_nil User.find_by_id(2) | |
179 | assert_equal User.anonymous, issue.journals.first.reload.user |
|
179 | assert_equal User.anonymous, issue.journals.first.reload.user | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | def test_destroy_should_update_journal_details_old_value |
|
182 | def test_destroy_should_update_journal_details_old_value | |
183 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) |
|
183 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo', :assigned_to_id => 2) | |
184 | issue.init_journal(User.find(1), "update") |
|
184 | issue.init_journal(User.find(1), "update") | |
@@ -188,12 +188,12 class UserTest < ActiveSupport::TestCase | |||||
188 | end |
|
188 | end | |
189 | journal_detail = JournalDetail.first(:order => 'id DESC') |
|
189 | journal_detail = JournalDetail.first(:order => 'id DESC') | |
190 | assert_equal '2', journal_detail.old_value |
|
190 | assert_equal '2', journal_detail.old_value | |
191 |
|
191 | |||
192 | User.find(2).destroy |
|
192 | User.find(2).destroy | |
193 | assert_nil User.find_by_id(2) |
|
193 | assert_nil User.find_by_id(2) | |
194 | assert_equal User.anonymous.id.to_s, journal_detail.reload.old_value |
|
194 | assert_equal User.anonymous.id.to_s, journal_detail.reload.old_value | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | def test_destroy_should_update_journal_details_value |
|
197 | def test_destroy_should_update_journal_details_value | |
198 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') |
|
198 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') | |
199 | issue.init_journal(User.find(1), "update") |
|
199 | issue.init_journal(User.find(1), "update") | |
@@ -203,79 +203,79 class UserTest < ActiveSupport::TestCase | |||||
203 | end |
|
203 | end | |
204 | journal_detail = JournalDetail.first(:order => 'id DESC') |
|
204 | journal_detail = JournalDetail.first(:order => 'id DESC') | |
205 | assert_equal '2', journal_detail.value |
|
205 | assert_equal '2', journal_detail.value | |
206 |
|
206 | |||
207 | User.find(2).destroy |
|
207 | User.find(2).destroy | |
208 | assert_nil User.find_by_id(2) |
|
208 | assert_nil User.find_by_id(2) | |
209 | assert_equal User.anonymous.id.to_s, journal_detail.reload.value |
|
209 | assert_equal User.anonymous.id.to_s, journal_detail.reload.value | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def test_destroy_should_update_messages |
|
212 | def test_destroy_should_update_messages | |
213 | board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board') |
|
213 | board = Board.create!(:project_id => 1, :name => 'Board', :description => 'Board') | |
214 | message = Message.create!(:board_id => board.id, :author_id => 2, :subject => 'foo', :content => 'foo') |
|
214 | message = Message.create!(:board_id => board.id, :author_id => 2, :subject => 'foo', :content => 'foo') | |
215 |
|
215 | |||
216 | User.find(2).destroy |
|
216 | User.find(2).destroy | |
217 | assert_nil User.find_by_id(2) |
|
217 | assert_nil User.find_by_id(2) | |
218 | assert_equal User.anonymous, message.reload.author |
|
218 | assert_equal User.anonymous, message.reload.author | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def test_destroy_should_update_news |
|
221 | def test_destroy_should_update_news | |
222 | news = News.create!(:project_id => 1, :author_id => 2, :title => 'foo', :description => 'foo') |
|
222 | news = News.create!(:project_id => 1, :author_id => 2, :title => 'foo', :description => 'foo') | |
223 |
|
223 | |||
224 | User.find(2).destroy |
|
224 | User.find(2).destroy | |
225 | assert_nil User.find_by_id(2) |
|
225 | assert_nil User.find_by_id(2) | |
226 | assert_equal User.anonymous, news.reload.author |
|
226 | assert_equal User.anonymous, news.reload.author | |
227 | end |
|
227 | end | |
228 |
|
228 | |||
229 | def test_destroy_should_delete_private_queries |
|
229 | def test_destroy_should_delete_private_queries | |
230 | query = Query.new(:name => 'foo', :is_public => false) |
|
230 | query = Query.new(:name => 'foo', :is_public => false) | |
231 | query.project_id = 1 |
|
231 | query.project_id = 1 | |
232 | query.user_id = 2 |
|
232 | query.user_id = 2 | |
233 | query.save! |
|
233 | query.save! | |
234 |
|
234 | |||
235 | User.find(2).destroy |
|
235 | User.find(2).destroy | |
236 | assert_nil User.find_by_id(2) |
|
236 | assert_nil User.find_by_id(2) | |
237 | assert_nil Query.find_by_id(query.id) |
|
237 | assert_nil Query.find_by_id(query.id) | |
238 | end |
|
238 | end | |
239 |
|
239 | |||
240 | def test_destroy_should_update_public_queries |
|
240 | def test_destroy_should_update_public_queries | |
241 | query = Query.new(:name => 'foo', :is_public => true) |
|
241 | query = Query.new(:name => 'foo', :is_public => true) | |
242 | query.project_id = 1 |
|
242 | query.project_id = 1 | |
243 | query.user_id = 2 |
|
243 | query.user_id = 2 | |
244 | query.save! |
|
244 | query.save! | |
245 |
|
245 | |||
246 | User.find(2).destroy |
|
246 | User.find(2).destroy | |
247 | assert_nil User.find_by_id(2) |
|
247 | assert_nil User.find_by_id(2) | |
248 | assert_equal User.anonymous, query.reload.user |
|
248 | assert_equal User.anonymous, query.reload.user | |
249 | end |
|
249 | end | |
250 |
|
250 | |||
251 | def test_destroy_should_update_time_entries |
|
251 | def test_destroy_should_update_time_entries | |
252 | entry = TimeEntry.new(:hours => '2', :spent_on => Date.today, :activity => TimeEntryActivity.create!(:name => 'foo')) |
|
252 | entry = TimeEntry.new(:hours => '2', :spent_on => Date.today, :activity => TimeEntryActivity.create!(:name => 'foo')) | |
253 | entry.project_id = 1 |
|
253 | entry.project_id = 1 | |
254 | entry.user_id = 2 |
|
254 | entry.user_id = 2 | |
255 | entry.save! |
|
255 | entry.save! | |
256 |
|
256 | |||
257 | User.find(2).destroy |
|
257 | User.find(2).destroy | |
258 | assert_nil User.find_by_id(2) |
|
258 | assert_nil User.find_by_id(2) | |
259 | assert_equal User.anonymous, entry.reload.user |
|
259 | assert_equal User.anonymous, entry.reload.user | |
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 | def test_destroy_should_delete_tokens |
|
262 | def test_destroy_should_delete_tokens | |
263 | token = Token.create!(:user_id => 2, :value => 'foo') |
|
263 | token = Token.create!(:user_id => 2, :value => 'foo') | |
264 |
|
264 | |||
265 | User.find(2).destroy |
|
265 | User.find(2).destroy | |
266 | assert_nil User.find_by_id(2) |
|
266 | assert_nil User.find_by_id(2) | |
267 | assert_nil Token.find_by_id(token.id) |
|
267 | assert_nil Token.find_by_id(token.id) | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | def test_destroy_should_delete_watchers |
|
270 | def test_destroy_should_delete_watchers | |
271 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') |
|
271 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'foo') | |
272 | watcher = Watcher.create!(:user_id => 2, :watchable => issue) |
|
272 | watcher = Watcher.create!(:user_id => 2, :watchable => issue) | |
273 |
|
273 | |||
274 | User.find(2).destroy |
|
274 | User.find(2).destroy | |
275 | assert_nil User.find_by_id(2) |
|
275 | assert_nil User.find_by_id(2) | |
276 | assert_nil Watcher.find_by_id(watcher.id) |
|
276 | assert_nil Watcher.find_by_id(watcher.id) | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def test_destroy_should_update_wiki_contents |
|
279 | def test_destroy_should_update_wiki_contents | |
280 | wiki_content = WikiContent.create!( |
|
280 | wiki_content = WikiContent.create!( | |
281 | :text => 'foo', |
|
281 | :text => 'foo', | |
@@ -286,7 +286,7 class UserTest < ActiveSupport::TestCase | |||||
286 | assert_difference 'WikiContent::Version.count' do |
|
286 | assert_difference 'WikiContent::Version.count' do | |
287 | wiki_content.save! |
|
287 | wiki_content.save! | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
290 | User.find(2).destroy |
|
290 | User.find(2).destroy | |
291 | assert_nil User.find_by_id(2) |
|
291 | assert_nil User.find_by_id(2) | |
292 | assert_equal User.anonymous, wiki_content.reload.author |
|
292 | assert_equal User.anonymous, wiki_content.reload.author | |
@@ -294,15 +294,15 class UserTest < ActiveSupport::TestCase | |||||
294 | assert_equal User.anonymous, version.reload.author |
|
294 | assert_equal User.anonymous, version.reload.author | |
295 | end |
|
295 | end | |
296 | end |
|
296 | end | |
297 |
|
297 | |||
298 | def test_destroy_should_nullify_issue_categories |
|
298 | def test_destroy_should_nullify_issue_categories | |
299 | category = IssueCategory.create!(:project_id => 1, :assigned_to_id => 2, :name => 'foo') |
|
299 | category = IssueCategory.create!(:project_id => 1, :assigned_to_id => 2, :name => 'foo') | |
300 |
|
300 | |||
301 | User.find(2).destroy |
|
301 | User.find(2).destroy | |
302 | assert_nil User.find_by_id(2) |
|
302 | assert_nil User.find_by_id(2) | |
303 | assert_nil category.reload.assigned_to_id |
|
303 | assert_nil category.reload.assigned_to_id | |
304 | end |
|
304 | end | |
305 |
|
305 | |||
306 | def test_destroy_should_nullify_changesets |
|
306 | def test_destroy_should_nullify_changesets | |
307 | changeset = Changeset.create!( |
|
307 | changeset = Changeset.create!( | |
308 | :repository => Repository::Subversion.create!( |
|
308 | :repository => Repository::Subversion.create!( | |
@@ -314,31 +314,31 class UserTest < ActiveSupport::TestCase | |||||
314 | :committer => 'jsmith' |
|
314 | :committer => 'jsmith' | |
315 | ) |
|
315 | ) | |
316 | assert_equal 2, changeset.user_id |
|
316 | assert_equal 2, changeset.user_id | |
317 |
|
317 | |||
318 | User.find(2).destroy |
|
318 | User.find(2).destroy | |
319 | assert_nil User.find_by_id(2) |
|
319 | assert_nil User.find_by_id(2) | |
320 | assert_nil changeset.reload.user_id |
|
320 | assert_nil changeset.reload.user_id | |
321 | end |
|
321 | end | |
322 |
|
322 | |||
323 | def test_anonymous_user_should_not_be_destroyable |
|
323 | def test_anonymous_user_should_not_be_destroyable | |
324 | assert_no_difference 'User.count' do |
|
324 | assert_no_difference 'User.count' do | |
325 | assert_equal false, User.anonymous.destroy |
|
325 | assert_equal false, User.anonymous.destroy | |
326 | end |
|
326 | end | |
327 | end |
|
327 | end | |
328 |
|
328 | |||
329 | def test_validate_login_presence |
|
329 | def test_validate_login_presence | |
330 | @admin.login = "" |
|
330 | @admin.login = "" | |
331 | assert !@admin.save |
|
331 | assert !@admin.save | |
332 | assert_equal 1, @admin.errors.count |
|
332 | assert_equal 1, @admin.errors.count | |
333 | end |
|
333 | end | |
334 |
|
334 | |||
335 | def test_validate_mail_notification_inclusion |
|
335 | def test_validate_mail_notification_inclusion | |
336 | u = User.new |
|
336 | u = User.new | |
337 | u.mail_notification = 'foo' |
|
337 | u.mail_notification = 'foo' | |
338 | u.save |
|
338 | u.save | |
339 | assert_not_nil u.errors.on(:mail_notification) |
|
339 | assert_not_nil u.errors.on(:mail_notification) | |
340 | end |
|
340 | end | |
341 |
|
341 | |||
342 | context "User#try_to_login" do |
|
342 | context "User#try_to_login" do | |
343 | should "fall-back to case-insensitive if user login is not found as-typed." do |
|
343 | should "fall-back to case-insensitive if user login is not found as-typed." do | |
344 | user = User.try_to_login("AdMin", "admin") |
|
344 | user = User.try_to_login("AdMin", "admin") | |
@@ -364,12 +364,12 class UserTest < ActiveSupport::TestCase | |||||
364 | assert_equal "admin", user.login |
|
364 | assert_equal "admin", user.login | |
365 | user.password = "hello" |
|
365 | user.password = "hello" | |
366 | assert user.save |
|
366 | assert user.save | |
367 |
|
367 | |||
368 | user = User.try_to_login("admin", "hello") |
|
368 | user = User.try_to_login("admin", "hello") | |
369 | assert_kind_of User, user |
|
369 | assert_kind_of User, user | |
370 | assert_equal "admin", user.login |
|
370 | assert_equal "admin", user.login | |
371 | end |
|
371 | end | |
372 |
|
372 | |||
373 | def test_name_format |
|
373 | def test_name_format | |
374 | assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) |
|
374 | assert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname) | |
375 | Setting.user_format = :firstname_lastname |
|
375 | Setting.user_format = :firstname_lastname | |
@@ -377,18 +377,18 class UserTest < ActiveSupport::TestCase | |||||
377 | Setting.user_format = :username |
|
377 | Setting.user_format = :username | |
378 | assert_equal 'jsmith', @jsmith.reload.name |
|
378 | assert_equal 'jsmith', @jsmith.reload.name | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | def test_lock |
|
381 | def test_lock | |
382 | user = User.try_to_login("jsmith", "jsmith") |
|
382 | user = User.try_to_login("jsmith", "jsmith") | |
383 | assert_equal @jsmith, user |
|
383 | assert_equal @jsmith, user | |
384 |
|
384 | |||
385 | @jsmith.status = User::STATUS_LOCKED |
|
385 | @jsmith.status = User::STATUS_LOCKED | |
386 | assert @jsmith.save |
|
386 | assert @jsmith.save | |
387 |
|
387 | |||
388 | user = User.try_to_login("jsmith", "jsmith") |
|
388 | user = User.try_to_login("jsmith", "jsmith") | |
389 |
assert_equal nil, user |
|
389 | assert_equal nil, user | |
390 | end |
|
390 | end | |
391 |
|
391 | |||
392 | context ".try_to_login" do |
|
392 | context ".try_to_login" do | |
393 | context "with good credentials" do |
|
393 | context "with good credentials" do | |
394 | should "return the user" do |
|
394 | should "return the user" do | |
@@ -397,21 +397,21 class UserTest < ActiveSupport::TestCase | |||||
397 | assert_equal "admin", user.login |
|
397 | assert_equal "admin", user.login | |
398 | end |
|
398 | end | |
399 | end |
|
399 | end | |
400 |
|
400 | |||
401 | context "with wrong credentials" do |
|
401 | context "with wrong credentials" do | |
402 | should "return nil" do |
|
402 | should "return nil" do | |
403 | assert_nil User.try_to_login("admin", "foo") |
|
403 | assert_nil User.try_to_login("admin", "foo") | |
404 | end |
|
404 | end | |
405 | end |
|
405 | end | |
406 | end |
|
406 | end | |
407 |
|
407 | |||
408 | if ldap_configured? |
|
408 | if ldap_configured? | |
409 | context "#try_to_login using LDAP" do |
|
409 | context "#try_to_login using LDAP" do | |
410 | context "with failed connection to the LDAP server" do |
|
410 | context "with failed connection to the LDAP server" do | |
411 | should "return nil" do |
|
411 | should "return nil" do | |
412 | @auth_source = AuthSourceLdap.find(1) |
|
412 | @auth_source = AuthSourceLdap.find(1) | |
413 | AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') |
|
413 | AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') | |
414 |
|
414 | |||
415 | assert_equal nil, User.try_to_login('edavis', 'wrong') |
|
415 | assert_equal nil, User.try_to_login('edavis', 'wrong') | |
416 | end |
|
416 | end | |
417 | end |
|
417 | end | |
@@ -421,7 +421,7 class UserTest < ActiveSupport::TestCase | |||||
421 | assert_equal nil, User.try_to_login('edavis', 'wrong') |
|
421 | assert_equal nil, User.try_to_login('edavis', 'wrong') | |
422 | end |
|
422 | end | |
423 | end |
|
423 | end | |
424 |
|
424 | |||
425 | context "on the fly registration" do |
|
425 | context "on the fly registration" do | |
426 | setup do |
|
426 | setup do | |
427 | @auth_source = AuthSourceLdap.find(1) |
|
427 | @auth_source = AuthSourceLdap.find(1) | |
@@ -434,12 +434,12 class UserTest < ActiveSupport::TestCase | |||||
434 | assert !user.admin? |
|
434 | assert !user.admin? | |
435 | end |
|
435 | end | |
436 | end |
|
436 | end | |
437 |
|
437 | |||
438 | should "retrieve existing user" do |
|
438 | should "retrieve existing user" do | |
439 | user = User.try_to_login('edavis', '123456') |
|
439 | user = User.try_to_login('edavis', '123456') | |
440 | user.admin = true |
|
440 | user.admin = true | |
441 | user.save! |
|
441 | user.save! | |
442 |
|
442 | |||
443 | assert_no_difference('User.count') do |
|
443 | assert_no_difference('User.count') do | |
444 | user = User.try_to_login('edavis', '123456') |
|
444 | user = User.try_to_login('edavis', '123456') | |
445 | assert user.admin? |
|
445 | assert user.admin? | |
@@ -452,7 +452,7 class UserTest < ActiveSupport::TestCase | |||||
452 | else |
|
452 | else | |
453 | puts "Skipping LDAP tests." |
|
453 | puts "Skipping LDAP tests." | |
454 | end |
|
454 | end | |
455 |
|
455 | |||
456 | def test_create_anonymous |
|
456 | def test_create_anonymous | |
457 | AnonymousUser.delete_all |
|
457 | AnonymousUser.delete_all | |
458 | anon = User.anonymous |
|
458 | anon = User.anonymous | |
@@ -466,12 +466,12 class UserTest < ActiveSupport::TestCase | |||||
466 | assert_nil @jsmith.rss_token |
|
466 | assert_nil @jsmith.rss_token | |
467 | key = @jsmith.rss_key |
|
467 | key = @jsmith.rss_key | |
468 | assert_equal 40, key.length |
|
468 | assert_equal 40, key.length | |
469 |
|
469 | |||
470 | @jsmith.reload |
|
470 | @jsmith.reload | |
471 | assert_equal key, @jsmith.rss_key |
|
471 | assert_equal key, @jsmith.rss_key | |
472 | end |
|
472 | end | |
473 |
|
473 | |||
474 |
|
474 | |||
475 | should_have_one :api_token |
|
475 | should_have_one :api_token | |
476 |
|
476 | |||
477 | context "User#api_key" do |
|
477 | context "User#api_key" do | |
@@ -490,7 +490,7 class UserTest < ActiveSupport::TestCase | |||||
490 | token = Token.generate!(:action => 'api') |
|
490 | token = Token.generate!(:action => 'api') | |
491 | user.api_token = token |
|
491 | user.api_token = token | |
492 | assert user.save |
|
492 | assert user.save | |
493 |
|
493 | |||
494 | assert_equal token.value, user.api_key |
|
494 | assert_equal token.value, user.api_key | |
495 | end |
|
495 | end | |
496 | end |
|
496 | end | |
@@ -514,7 +514,7 class UserTest < ActiveSupport::TestCase | |||||
514 | token = Token.generate!(:action => 'api') |
|
514 | token = Token.generate!(:action => 'api') | |
515 | user.api_token = token |
|
515 | user.api_token = token | |
516 | user.save |
|
516 | user.save | |
517 |
|
517 | |||
518 | assert_equal user, User.find_by_api_key(token.value) |
|
518 | assert_equal user, User.find_by_api_key(token.value) | |
519 | end |
|
519 | end | |
520 | end |
|
520 | end | |
@@ -524,11 +524,11 class UserTest < ActiveSupport::TestCase | |||||
524 | roles = @jsmith.roles_for_project(Project.find(1)) |
|
524 | roles = @jsmith.roles_for_project(Project.find(1)) | |
525 | assert_kind_of Role, roles.first |
|
525 | assert_kind_of Role, roles.first | |
526 | assert_equal "Manager", roles.first.name |
|
526 | assert_equal "Manager", roles.first.name | |
527 |
|
527 | |||
528 | # user with no role |
|
528 | # user with no role | |
529 | assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} |
|
529 | assert_nil @dlopper.roles_for_project(Project.find(2)).detect {|role| role.member?} | |
530 | end |
|
530 | end | |
531 |
|
531 | |||
532 | def test_projects_by_role_for_user_with_role |
|
532 | def test_projects_by_role_for_user_with_role | |
533 | user = User.find(2) |
|
533 | user = User.find(2) | |
534 | assert_kind_of Hash, user.projects_by_role |
|
534 | assert_kind_of Hash, user.projects_by_role | |
@@ -536,12 +536,12 class UserTest < ActiveSupport::TestCase | |||||
536 | assert_equal [1,5], user.projects_by_role[Role.find(1)].collect(&:id).sort |
|
536 | assert_equal [1,5], user.projects_by_role[Role.find(1)].collect(&:id).sort | |
537 | assert_equal [2], user.projects_by_role[Role.find(2)].collect(&:id).sort |
|
537 | assert_equal [2], user.projects_by_role[Role.find(2)].collect(&:id).sort | |
538 | end |
|
538 | end | |
539 |
|
539 | |||
540 | def test_projects_by_role_for_user_with_no_role |
|
540 | def test_projects_by_role_for_user_with_no_role | |
541 | user = User.generate! |
|
541 | user = User.generate! | |
542 | assert_equal({}, user.projects_by_role) |
|
542 | assert_equal({}, user.projects_by_role) | |
543 | end |
|
543 | end | |
544 |
|
544 | |||
545 | def test_projects_by_role_for_anonymous |
|
545 | def test_projects_by_role_for_anonymous | |
546 | assert_equal({}, User.anonymous.projects_by_role) |
|
546 | assert_equal({}, User.anonymous.projects_by_role) | |
547 | end |
|
547 | end | |
@@ -552,13 +552,13 class UserTest < ActiveSupport::TestCase | |||||
552 | # with memberships |
|
552 | # with memberships | |
553 | assert_equal 6, User.find(2).valid_notification_options.size |
|
553 | assert_equal 6, User.find(2).valid_notification_options.size | |
554 | end |
|
554 | end | |
555 |
|
555 | |||
556 | def test_valid_notification_options_class_method |
|
556 | def test_valid_notification_options_class_method | |
557 | assert_equal 5, User.valid_notification_options.size |
|
557 | assert_equal 5, User.valid_notification_options.size | |
558 | assert_equal 5, User.valid_notification_options(User.find(7)).size |
|
558 | assert_equal 5, User.valid_notification_options(User.find(7)).size | |
559 | assert_equal 6, User.valid_notification_options(User.find(2)).size |
|
559 | assert_equal 6, User.valid_notification_options(User.find(2)).size | |
560 | end |
|
560 | end | |
561 |
|
561 | |||
562 | def test_mail_notification_all |
|
562 | def test_mail_notification_all | |
563 | @jsmith.mail_notification = 'all' |
|
563 | @jsmith.mail_notification = 'all' | |
564 | @jsmith.notified_project_ids = [] |
|
564 | @jsmith.notified_project_ids = [] | |
@@ -566,7 +566,7 class UserTest < ActiveSupport::TestCase | |||||
566 | @jsmith.reload |
|
566 | @jsmith.reload | |
567 | assert @jsmith.projects.first.recipients.include?(@jsmith.mail) |
|
567 | assert @jsmith.projects.first.recipients.include?(@jsmith.mail) | |
568 | end |
|
568 | end | |
569 |
|
569 | |||
570 | def test_mail_notification_selected |
|
570 | def test_mail_notification_selected | |
571 | @jsmith.mail_notification = 'selected' |
|
571 | @jsmith.mail_notification = 'selected' | |
572 | @jsmith.notified_project_ids = [1] |
|
572 | @jsmith.notified_project_ids = [1] | |
@@ -574,7 +574,7 class UserTest < ActiveSupport::TestCase | |||||
574 | @jsmith.reload |
|
574 | @jsmith.reload | |
575 | assert Project.find(1).recipients.include?(@jsmith.mail) |
|
575 | assert Project.find(1).recipients.include?(@jsmith.mail) | |
576 | end |
|
576 | end | |
577 |
|
577 | |||
578 | def test_mail_notification_only_my_events |
|
578 | def test_mail_notification_only_my_events | |
579 | @jsmith.mail_notification = 'only_my_events' |
|
579 | @jsmith.mail_notification = 'only_my_events' | |
580 | @jsmith.notified_project_ids = [] |
|
580 | @jsmith.notified_project_ids = [] | |
@@ -582,7 +582,7 class UserTest < ActiveSupport::TestCase | |||||
582 | @jsmith.reload |
|
582 | @jsmith.reload | |
583 | assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) |
|
583 | assert !@jsmith.projects.first.recipients.include?(@jsmith.mail) | |
584 | end |
|
584 | end | |
585 |
|
585 | |||
586 | def test_comments_sorting_preference |
|
586 | def test_comments_sorting_preference | |
587 | assert !@jsmith.wants_comments_in_reverse_order? |
|
587 | assert !@jsmith.wants_comments_in_reverse_order? | |
588 | @jsmith.pref.comments_sorting = 'asc' |
|
588 | @jsmith.pref.comments_sorting = 'asc' | |
@@ -590,13 +590,13 class UserTest < ActiveSupport::TestCase | |||||
590 | @jsmith.pref.comments_sorting = 'desc' |
|
590 | @jsmith.pref.comments_sorting = 'desc' | |
591 | assert @jsmith.wants_comments_in_reverse_order? |
|
591 | assert @jsmith.wants_comments_in_reverse_order? | |
592 | end |
|
592 | end | |
593 |
|
593 | |||
594 | def test_find_by_mail_should_be_case_insensitive |
|
594 | def test_find_by_mail_should_be_case_insensitive | |
595 | u = User.find_by_mail('JSmith@somenet.foo') |
|
595 | u = User.find_by_mail('JSmith@somenet.foo') | |
596 | assert_not_nil u |
|
596 | assert_not_nil u | |
597 | assert_equal 'jsmith@somenet.foo', u.mail |
|
597 | assert_equal 'jsmith@somenet.foo', u.mail | |
598 | end |
|
598 | end | |
599 |
|
599 | |||
600 | def test_random_password |
|
600 | def test_random_password | |
601 | u = User.new |
|
601 | u = User.new | |
602 | u.random_password |
|
602 | u.random_password | |
@@ -612,7 +612,7 class UserTest < ActiveSupport::TestCase | |||||
612 |
|
612 | |||
613 | should "delegate to the auth source" do |
|
613 | should "delegate to the auth source" do | |
614 | user = User.generate_with_protected! |
|
614 | user = User.generate_with_protected! | |
615 |
|
615 | |||
616 | allowed_auth_source = AuthSource.generate! |
|
616 | allowed_auth_source = AuthSource.generate! | |
617 | def allowed_auth_source.allow_password_changes?; true; end |
|
617 | def allowed_auth_source.allow_password_changes?; true; end | |
618 |
|
618 | |||
@@ -629,7 +629,7 class UserTest < ActiveSupport::TestCase | |||||
629 | end |
|
629 | end | |
630 |
|
630 | |||
631 | end |
|
631 | end | |
632 |
|
632 | |||
633 | context "#allowed_to?" do |
|
633 | context "#allowed_to?" do | |
634 | context "with a unique project" do |
|
634 | context "with a unique project" do | |
635 | should "return false if project is archived" do |
|
635 | should "return false if project is archived" do | |
@@ -637,14 +637,14 class UserTest < ActiveSupport::TestCase | |||||
637 | Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED) |
|
637 | Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED) | |
638 | assert ! @admin.allowed_to?(:view_issues, Project.find(1)) |
|
638 | assert ! @admin.allowed_to?(:view_issues, Project.find(1)) | |
639 | end |
|
639 | end | |
640 |
|
640 | |||
641 | should "return false if related module is disabled" do |
|
641 | should "return false if related module is disabled" do | |
642 | project = Project.find(1) |
|
642 | project = Project.find(1) | |
643 | project.enabled_module_names = ["issue_tracking"] |
|
643 | project.enabled_module_names = ["issue_tracking"] | |
644 | assert @admin.allowed_to?(:add_issues, project) |
|
644 | assert @admin.allowed_to?(:add_issues, project) | |
645 | assert ! @admin.allowed_to?(:view_wiki_pages, project) |
|
645 | assert ! @admin.allowed_to?(:view_wiki_pages, project) | |
646 | end |
|
646 | end | |
647 |
|
647 | |||
648 | should "authorize nearly everything for admin users" do |
|
648 | should "authorize nearly everything for admin users" do | |
649 | project = Project.find(1) |
|
649 | project = Project.find(1) | |
650 | assert ! @admin.member_of?(project) |
|
650 | assert ! @admin.member_of?(project) | |
@@ -652,7 +652,7 class UserTest < ActiveSupport::TestCase | |||||
652 | assert @admin.allowed_to?(p.to_sym, project) |
|
652 | assert @admin.allowed_to?(p.to_sym, project) | |
653 | end |
|
653 | end | |
654 | end |
|
654 | end | |
655 |
|
655 | |||
656 | should "authorize normal users depending on their roles" do |
|
656 | should "authorize normal users depending on their roles" do | |
657 | project = Project.find(1) |
|
657 | project = Project.find(1) | |
658 | assert @jsmith.allowed_to?(:delete_messages, project) #Manager |
|
658 | assert @jsmith.allowed_to?(:delete_messages, project) #Manager | |
@@ -664,19 +664,19 class UserTest < ActiveSupport::TestCase | |||||
664 | should "return false if array is empty" do |
|
664 | should "return false if array is empty" do | |
665 | assert ! @admin.allowed_to?(:view_project, []) |
|
665 | assert ! @admin.allowed_to?(:view_project, []) | |
666 | end |
|
666 | end | |
667 |
|
667 | |||
668 | should "return true only if user has permission on all these projects" do |
|
668 | should "return true only if user has permission on all these projects" do | |
669 | assert @admin.allowed_to?(:view_project, Project.all) |
|
669 | assert @admin.allowed_to?(:view_project, Project.all) | |
670 | assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) |
|
670 | assert ! @dlopper.allowed_to?(:view_project, Project.all) #cannot see Project(2) | |
671 | assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere |
|
671 | assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere | |
672 | assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers |
|
672 | assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers | |
673 | end |
|
673 | end | |
674 |
|
674 | |||
675 | should "behave correctly with arrays of 1 project" do |
|
675 | should "behave correctly with arrays of 1 project" do | |
676 | assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) |
|
676 | assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first]) | |
677 | end |
|
677 | end | |
678 | end |
|
678 | end | |
679 |
|
679 | |||
680 | context "with options[:global]" do |
|
680 | context "with options[:global]" do | |
681 | should "authorize if user has at least one role that has this permission" do |
|
681 | should "authorize if user has at least one role that has this permission" do | |
682 | @dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere |
|
682 | @dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere | |
@@ -689,7 +689,7 class UserTest < ActiveSupport::TestCase | |||||
689 | end |
|
689 | end | |
690 | end |
|
690 | end | |
691 | end |
|
691 | end | |
692 |
|
692 | |||
693 | context "User#notify_about?" do |
|
693 | context "User#notify_about?" do | |
694 | context "Issues" do |
|
694 | context "Issues" do | |
695 | setup do |
|
695 | setup do | |
@@ -703,58 +703,58 class UserTest < ActiveSupport::TestCase | |||||
703 | @author.update_attribute(:mail_notification, 'all') |
|
703 | @author.update_attribute(:mail_notification, 'all') | |
704 | assert @author.notify_about?(@issue) |
|
704 | assert @author.notify_about?(@issue) | |
705 | end |
|
705 | end | |
706 |
|
706 | |||
707 | should "be false for a user with :none" do |
|
707 | should "be false for a user with :none" do | |
708 | @author.update_attribute(:mail_notification, 'none') |
|
708 | @author.update_attribute(:mail_notification, 'none') | |
709 | assert ! @author.notify_about?(@issue) |
|
709 | assert ! @author.notify_about?(@issue) | |
710 | end |
|
710 | end | |
711 |
|
711 | |||
712 | should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do |
|
712 | should "be false for a user with :only_my_events and isn't an author, creator, or assignee" do | |
713 | @user = User.generate_with_protected!(:mail_notification => 'only_my_events') |
|
713 | @user = User.generate_with_protected!(:mail_notification => 'only_my_events') | |
714 | Member.create!(:user => @user, :project => @project, :role_ids => [1]) |
|
714 | Member.create!(:user => @user, :project => @project, :role_ids => [1]) | |
715 | assert ! @user.notify_about?(@issue) |
|
715 | assert ! @user.notify_about?(@issue) | |
716 | end |
|
716 | end | |
717 |
|
717 | |||
718 | should "be true for a user with :only_my_events and is the author" do |
|
718 | should "be true for a user with :only_my_events and is the author" do | |
719 | @author.update_attribute(:mail_notification, 'only_my_events') |
|
719 | @author.update_attribute(:mail_notification, 'only_my_events') | |
720 | assert @author.notify_about?(@issue) |
|
720 | assert @author.notify_about?(@issue) | |
721 | end |
|
721 | end | |
722 |
|
722 | |||
723 | should "be true for a user with :only_my_events and is the assignee" do |
|
723 | should "be true for a user with :only_my_events and is the assignee" do | |
724 | @assignee.update_attribute(:mail_notification, 'only_my_events') |
|
724 | @assignee.update_attribute(:mail_notification, 'only_my_events') | |
725 | assert @assignee.notify_about?(@issue) |
|
725 | assert @assignee.notify_about?(@issue) | |
726 | end |
|
726 | end | |
727 |
|
727 | |||
728 | should "be true for a user with :only_assigned and is the assignee" do |
|
728 | should "be true for a user with :only_assigned and is the assignee" do | |
729 | @assignee.update_attribute(:mail_notification, 'only_assigned') |
|
729 | @assignee.update_attribute(:mail_notification, 'only_assigned') | |
730 | assert @assignee.notify_about?(@issue) |
|
730 | assert @assignee.notify_about?(@issue) | |
731 | end |
|
731 | end | |
732 |
|
732 | |||
733 | should "be false for a user with :only_assigned and is not the assignee" do |
|
733 | should "be false for a user with :only_assigned and is not the assignee" do | |
734 | @author.update_attribute(:mail_notification, 'only_assigned') |
|
734 | @author.update_attribute(:mail_notification, 'only_assigned') | |
735 | assert ! @author.notify_about?(@issue) |
|
735 | assert ! @author.notify_about?(@issue) | |
736 | end |
|
736 | end | |
737 |
|
737 | |||
738 | should "be true for a user with :only_owner and is the author" do |
|
738 | should "be true for a user with :only_owner and is the author" do | |
739 | @author.update_attribute(:mail_notification, 'only_owner') |
|
739 | @author.update_attribute(:mail_notification, 'only_owner') | |
740 | assert @author.notify_about?(@issue) |
|
740 | assert @author.notify_about?(@issue) | |
741 | end |
|
741 | end | |
742 |
|
742 | |||
743 | should "be false for a user with :only_owner and is not the author" do |
|
743 | should "be false for a user with :only_owner and is not the author" do | |
744 | @assignee.update_attribute(:mail_notification, 'only_owner') |
|
744 | @assignee.update_attribute(:mail_notification, 'only_owner') | |
745 | assert ! @assignee.notify_about?(@issue) |
|
745 | assert ! @assignee.notify_about?(@issue) | |
746 | end |
|
746 | end | |
747 |
|
747 | |||
748 | should "be true for a user with :selected and is the author" do |
|
748 | should "be true for a user with :selected and is the author" do | |
749 | @author.update_attribute(:mail_notification, 'selected') |
|
749 | @author.update_attribute(:mail_notification, 'selected') | |
750 | assert @author.notify_about?(@issue) |
|
750 | assert @author.notify_about?(@issue) | |
751 | end |
|
751 | end | |
752 |
|
752 | |||
753 | should "be true for a user with :selected and is the assignee" do |
|
753 | should "be true for a user with :selected and is the assignee" do | |
754 | @assignee.update_attribute(:mail_notification, 'selected') |
|
754 | @assignee.update_attribute(:mail_notification, 'selected') | |
755 | assert @assignee.notify_about?(@issue) |
|
755 | assert @assignee.notify_about?(@issue) | |
756 | end |
|
756 | end | |
757 |
|
757 | |||
758 | should "be false for a user with :selected and is not the author or assignee" do |
|
758 | should "be false for a user with :selected and is not the author or assignee" do | |
759 | @user = User.generate_with_protected!(:mail_notification => 'selected') |
|
759 | @user = User.generate_with_protected!(:mail_notification => 'selected') | |
760 | Member.create!(:user => @user, :project => @project, :role_ids => [1]) |
|
760 | Member.create!(:user => @user, :project => @project, :role_ids => [1]) | |
@@ -773,9 +773,9 class UserTest < ActiveSupport::TestCase | |||||
773 | user.salt = nil |
|
773 | user.salt = nil | |
774 | user.hashed_password = User.hash_password("unsalted") |
|
774 | user.hashed_password = User.hash_password("unsalted") | |
775 | user.save! |
|
775 | user.save! | |
776 |
|
776 | |||
777 | User.salt_unsalted_passwords! |
|
777 | User.salt_unsalted_passwords! | |
778 |
|
778 | |||
779 | user.reload |
|
779 | user.reload | |
780 | # Salt added |
|
780 | # Salt added | |
781 | assert !user.salt.blank? |
|
781 | assert !user.salt.blank? | |
@@ -783,9 +783,9 class UserTest < ActiveSupport::TestCase | |||||
783 | assert user.check_password?("unsalted") |
|
783 | assert user.check_password?("unsalted") | |
784 | assert_equal user, User.try_to_login(user.login, "unsalted") |
|
784 | assert_equal user, User.try_to_login(user.login, "unsalted") | |
785 | end |
|
785 | end | |
786 |
|
786 | |||
787 | if Object.const_defined?(:OpenID) |
|
787 | if Object.const_defined?(:OpenID) | |
788 |
|
788 | |||
789 | def test_setting_identity_url |
|
789 | def test_setting_identity_url | |
790 | normalized_open_id_url = 'http://example.com/' |
|
790 | normalized_open_id_url = 'http://example.com/' | |
791 | u = User.new( :identity_url => 'http://example.com/' ) |
|
791 | u = User.new( :identity_url => 'http://example.com/' ) | |
@@ -803,18 +803,18 class UserTest < ActiveSupport::TestCase | |||||
803 | u = User.new( :identity_url => 'example.com' ) |
|
803 | u = User.new( :identity_url => 'example.com' ) | |
804 | assert_equal normalized_open_id_url, u.identity_url |
|
804 | assert_equal normalized_open_id_url, u.identity_url | |
805 | end |
|
805 | end | |
806 |
|
806 | |||
807 | def test_setting_blank_identity_url |
|
807 | def test_setting_blank_identity_url | |
808 | u = User.new( :identity_url => 'example.com' ) |
|
808 | u = User.new( :identity_url => 'example.com' ) | |
809 | u.identity_url = '' |
|
809 | u.identity_url = '' | |
810 | assert u.identity_url.blank? |
|
810 | assert u.identity_url.blank? | |
811 | end |
|
811 | end | |
812 |
|
812 | |||
813 | def test_setting_invalid_identity_url |
|
813 | def test_setting_invalid_identity_url | |
814 | u = User.new( :identity_url => 'this is not an openid url' ) |
|
814 | u = User.new( :identity_url => 'this is not an openid url' ) | |
815 | assert u.identity_url.blank? |
|
815 | assert u.identity_url.blank? | |
816 | end |
|
816 | end | |
817 |
|
817 | |||
818 | else |
|
818 | else | |
819 | puts "Skipping openid tests." |
|
819 | puts "Skipping openid tests." | |
820 | end |
|
820 | end |
General Comments 0
You need to be logged in to leave comments.
Login now