diff options
| author | simon <simon@zagal.(none)> | 2009-02-08 23:15:11 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-15 20:22:01 +0100 |
| commit | 9f94a70c3e3d9bf766cb9663b0a904d30a190d85 (patch) | |
| tree | 4b4bbf567ec60a939d024b083b478d72476700a5 /test/unit | |
| parent | 48ffd4eb446bcaeba7651758ec3002f342702249 (diff) | |
* initial commit of the stripped restful-authentication
* http basic auth and login from cookie have been removed
* no it does not work yet, it's so f*cking secure, it won't even let legitimate users login
Diffstat (limited to 'test/unit')
| -rw-r--r-- | test/unit/user_test.rb | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index a64d2d3..47e3129 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb | |||
| @@ -1,8 +1,64 @@ | |||
| 1 | require 'test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | ||
| 3 | class UserTest < ActiveSupport::TestCase | 3 | class UserTest < ActiveSupport::TestCase |
| 4 | # Replace this with your real tests. | 4 | # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead. |
| 5 | test "the truth" do | 5 | # Then, you can remove it from this and the functional test. |
| 6 | assert true | 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.on(:login) | ||
| 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.on(:password) | ||
| 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.on(:password_confirmation) | ||
| 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.on(:email) | ||
| 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 | ||
| 7 | end | 63 | end |
| 8 | end | 64 | end |
