Commit 87318d7b8365ce46c6bb319f959e5e690b195a4a
1 parent
43ba0520
Exists in
master
and in
23 other branches
person-and-users-tests: refactor
Showing
2 changed files
with
13 additions
and
22 deletions
Show diff stats
test/unit/person_test.rb
| ... | ... | @@ -1342,12 +1342,12 @@ class PersonTest < ActiveSupport::TestCase |
| 1342 | 1342 | (1..5).each {|i| |
| 1343 | 1343 | u = create_user('user'+i.to_s) |
| 1344 | 1344 | e.add_admin(u.person) |
| 1345 | - admins << u.person | |
| 1345 | + admins << u.person | |
| 1346 | 1346 | } |
| 1347 | 1347 | (6..10).each {|i| |
| 1348 | 1348 | u = create_user('user'+i.to_s) |
| 1349 | 1349 | } |
| 1350 | - assert_equal admins, Person.admins | |
| 1350 | + assert_equal admins, Person.admins | |
| 1351 | 1351 | end |
| 1352 | 1352 | |
| 1353 | 1353 | should 'activated named_scope return persons who are activated users' do |
| ... | ... | @@ -1356,17 +1356,14 @@ class PersonTest < ActiveSupport::TestCase |
| 1356 | 1356 | activated = [] |
| 1357 | 1357 | (1..5).each {|i| |
| 1358 | 1358 | u = create_user('user'+i.to_s) |
| 1359 | - u.activated_at = Time.now.utc | |
| 1360 | - u.activation_code = nil | |
| 1361 | - u.save! | |
| 1362 | - activated << u.person | |
| 1359 | + u.activate | |
| 1360 | + activated << u.person | |
| 1363 | 1361 | } |
| 1364 | 1362 | (6..10).each {|i| |
| 1365 | 1363 | u = create_user('user'+i.to_s) |
| 1366 | - u.activated_at = nil | |
| 1367 | - u.save! | |
| 1364 | + u.deactivate | |
| 1368 | 1365 | } |
| 1369 | - assert_equal activated, Person.activated | |
| 1366 | + assert_equal activated, Person.activated | |
| 1370 | 1367 | end |
| 1371 | 1368 | |
| 1372 | 1369 | should 'deactivated named_scope return persons who are deactivated users' do |
| ... | ... | @@ -1375,16 +1372,13 @@ class PersonTest < ActiveSupport::TestCase |
| 1375 | 1372 | deactivated = [] |
| 1376 | 1373 | (1..5).each {|i| |
| 1377 | 1374 | u = create_user('user'+i.to_s) |
| 1378 | - u.activated_at = nil | |
| 1379 | - u.save! | |
| 1380 | - deactivated << u.person | |
| 1375 | + u.deactivate | |
| 1376 | + deactivated << u.person | |
| 1381 | 1377 | } |
| 1382 | 1378 | (6..10).each {|i| |
| 1383 | 1379 | u = create_user('user'+i.to_s) |
| 1384 | - u.activated_at = Time.now.utc | |
| 1385 | - u.activation_code = nil | |
| 1386 | - u.save! | |
| 1380 | + u.activate | |
| 1387 | 1381 | } |
| 1388 | - assert_equal deactivated, Person.deactivated | |
| 1382 | + assert_equal deactivated, Person.deactivated | |
| 1389 | 1383 | end |
| 1390 | 1384 | end | ... | ... |
test/unit/user_test.rb
| ... | ... | @@ -520,8 +520,7 @@ class UserTest < ActiveSupport::TestCase |
| 520 | 520 | |
| 521 | 521 | should 'deactivate an user' do |
| 522 | 522 | user = new_user |
| 523 | - user.activated_at = Time.now.utc | |
| 524 | - user.person.visible = true | |
| 523 | + user.activate | |
| 525 | 524 | assert user.deactivate |
| 526 | 525 | assert_nil user.activated_at |
| 527 | 526 | assert !user.person.visible |
| ... | ... | @@ -529,14 +528,12 @@ class UserTest < ActiveSupport::TestCase |
| 529 | 528 | |
| 530 | 529 | should 'return if the user is deactivated' do |
| 531 | 530 | user = new_user |
| 532 | - user.activated_at = Time.now.utc | |
| 533 | - user.activation_code = nil | |
| 534 | - user.person.visible = true | |
| 531 | + user.activate | |
| 535 | 532 | assert user.activated? |
| 536 | 533 | user.deactivate |
| 537 | 534 | assert !user.activated? |
| 538 | 535 | end |
| 539 | - | |
| 536 | + | |
| 540 | 537 | should 'activate right after creation when confirmation is not required' do |
| 541 | 538 | e = Environment.default |
| 542 | 539 | e.enable('skip_new_user_email_confirmation') | ... | ... |