diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-25 17:51:45 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-25 17:51:45 +0200 |
| commit | 0818a3057b0a91e422158d828026c941b4e10622 (patch) | |
| tree | 9ed98d52bd577d3f36dd7a1ce8048d280a36062e /test/models/user_test.rb | |
| parent | 26030c71c7b300c30367222f263d74b8d2142ecf (diff) | |
Rails 5.2 test updates
- Rename test/functional → test/controllers, test/unit → test/models
- Remove test/performance/browsing_test.rb (performance_test_help removed)
- Fix use_transactional_fixtures → use_transactional_tests
- Remove use_instantiated_fixtures (removed in Rails 5)
- Fix ActiveRecord::Fixtures → FixtureSet
- Fix controller test params syntax: add params: {} wrapper throughout
- Fix assert_select targets for aggregator test
- Fix test_update_a_draft_with_changing_the_template: draft → head
- Add test_node.reload after children.create! (awesome_nested_set bug)
- Add before/after count pattern for create tests (transactional isolation)
- Known failures: 5 tests affected by Rails 5 transactional test isolation
Diffstat (limited to 'test/models/user_test.rb')
| -rw-r--r-- | test/models/user_test.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..bd5d059 --- /dev/null +++ b/test/models/user_test.rb | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | |||
| 3 | class UserTest < ActiveSupport::TestCase | ||
| 4 | # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead. | ||
| 5 | # Then, you can remove it from this and the functional test. | ||
| 6 | include AuthenticatedTestHelper | ||
| 7 | fixtures :users | ||
| 8 | |||
| 9 | def test_should_create_user | ||
| 10 | assert_difference 'User.count' do | ||
| 11 | user = create_user | ||
| 12 | assert !user.new_record?, "#{user.errors.full_messages.to_sentence}" | ||
| 13 | end | ||
| 14 | end | ||
| 15 | |||
| 16 | def test_should_require_login | ||
| 17 | assert_no_difference 'User.count' do | ||
| 18 | u = create_user(:login => nil) | ||
| 19 | assert u.errors[:login].any? | ||
| 20 | end | ||
| 21 | end | ||
| 22 | |||
| 23 | def test_should_require_password | ||
| 24 | assert_no_difference 'User.count' do | ||
| 25 | u = create_user(:password => nil) | ||
| 26 | assert u.errors[:password].any? | ||
| 27 | end | ||
| 28 | end | ||
| 29 | |||
| 30 | def test_should_require_password_confirmation | ||
| 31 | assert_no_difference 'User.count' do | ||
| 32 | u = create_user(:password_confirmation => nil) | ||
| 33 | assert u.errors[:password_confirmation].any? | ||
| 34 | end | ||
| 35 | end | ||
| 36 | |||
| 37 | def test_should_require_email | ||
| 38 | assert_no_difference 'User.count' do | ||
| 39 | u = create_user(:email => nil) | ||
| 40 | assert u.errors[:email].any? | ||
| 41 | end | ||
| 42 | end | ||
| 43 | |||
| 44 | def test_should_reset_password | ||
| 45 | users(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password') | ||
| 46 | assert_equal users(:quentin), User.authenticate('quentin', 'new password') | ||
| 47 | end | ||
| 48 | |||
| 49 | def test_should_not_rehash_password | ||
| 50 | users(:quentin).update_attributes(:login => 'quentin2') | ||
| 51 | assert_equal users(:quentin), User.authenticate('quentin2', 'monkey') | ||
| 52 | end | ||
| 53 | |||
| 54 | def test_should_authenticate_user | ||
| 55 | assert_equal users(:quentin), User.authenticate('quentin', 'monkey') | ||
| 56 | end | ||
| 57 | |||
| 58 | protected | ||
| 59 | def create_user(options = {}) | ||
| 60 | record = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire69', :password_confirmation => 'quire69' }.merge(options)) | ||
| 61 | record.save | ||
| 62 | record | ||
| 63 | end | ||
| 64 | end | ||
