authlogic 0.10.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of authlogic might be problematic. Click here for more details.

Files changed (102) hide show
  1. data/CHANGELOG.rdoc +47 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest +100 -0
  4. data/README.rdoc +292 -0
  5. data/Rakefile +15 -0
  6. data/authlogic.gemspec +38 -0
  7. data/init.rb +1 -0
  8. data/lib/authlogic.rb +25 -0
  9. data/lib/authlogic/active_record/acts_as_authentic.rb +265 -0
  10. data/lib/authlogic/active_record/authenticates_many.rb +19 -0
  11. data/lib/authlogic/active_record/scoped_session.rb +28 -0
  12. data/lib/authlogic/controller_adapters/abstract_adapter.rb +25 -0
  13. data/lib/authlogic/controller_adapters/rails_adapter.rb +39 -0
  14. data/lib/authlogic/session/active_record_trickery.rb +26 -0
  15. data/lib/authlogic/session/base.rb +510 -0
  16. data/lib/authlogic/session/callbacks.rb +56 -0
  17. data/lib/authlogic/session/config.rb +237 -0
  18. data/lib/authlogic/session/errors.rb +18 -0
  19. data/lib/authlogic/sha512_crypto_provider.rb +18 -0
  20. data/lib/authlogic/version.rb +56 -0
  21. data/test_app/README +256 -0
  22. data/test_app/Rakefile +10 -0
  23. data/test_app/app/controllers/application.rb +72 -0
  24. data/test_app/app/controllers/companies_controller.rb +2 -0
  25. data/test_app/app/controllers/user_sessions_controller.rb +25 -0
  26. data/test_app/app/controllers/users_controller.rb +61 -0
  27. data/test_app/app/helpers/application_helper.rb +3 -0
  28. data/test_app/app/helpers/companies_helper.rb +2 -0
  29. data/test_app/app/helpers/user_sessions_helper.rb +2 -0
  30. data/test_app/app/helpers/users_helper.rb +2 -0
  31. data/test_app/app/models/company.rb +4 -0
  32. data/test_app/app/models/project.rb +3 -0
  33. data/test_app/app/models/user.rb +5 -0
  34. data/test_app/app/models/user_session.rb +3 -0
  35. data/test_app/app/views/layouts/application.html.erb +27 -0
  36. data/test_app/app/views/user_sessions/new.html.erb +15 -0
  37. data/test_app/app/views/users/_form.erb +15 -0
  38. data/test_app/app/views/users/edit.html.erb +8 -0
  39. data/test_app/app/views/users/new.html.erb +8 -0
  40. data/test_app/app/views/users/show.html.erb +29 -0
  41. data/test_app/config/boot.rb +109 -0
  42. data/test_app/config/database.yml +19 -0
  43. data/test_app/config/environment.rb +69 -0
  44. data/test_app/config/environments/development.rb +17 -0
  45. data/test_app/config/environments/production.rb +22 -0
  46. data/test_app/config/environments/test.rb +22 -0
  47. data/test_app/config/initializers/inflections.rb +10 -0
  48. data/test_app/config/initializers/mime_types.rb +5 -0
  49. data/test_app/config/initializers/new_rails_defaults.rb +17 -0
  50. data/test_app/config/routes.rb +11 -0
  51. data/test_app/db/development.sqlite3 +0 -0
  52. data/test_app/db/migrate/20081023040052_create_users.rb +20 -0
  53. data/test_app/db/migrate/20081103003828_create_companies.rb +14 -0
  54. data/test_app/db/migrate/20081103003834_create_projects.rb +18 -0
  55. data/test_app/db/schema.rb +46 -0
  56. data/test_app/db/test.sqlite3 +0 -0
  57. data/test_app/doc/README_FOR_APP +2 -0
  58. data/test_app/public/404.html +30 -0
  59. data/test_app/public/422.html +30 -0
  60. data/test_app/public/500.html +30 -0
  61. data/test_app/public/dispatch.cgi +10 -0
  62. data/test_app/public/dispatch.fcgi +24 -0
  63. data/test_app/public/dispatch.rb +10 -0
  64. data/test_app/public/favicon.ico +0 -0
  65. data/test_app/public/images/rails.png +0 -0
  66. data/test_app/public/javascripts/application.js +2 -0
  67. data/test_app/public/javascripts/controls.js +963 -0
  68. data/test_app/public/javascripts/dragdrop.js +972 -0
  69. data/test_app/public/javascripts/effects.js +1120 -0
  70. data/test_app/public/javascripts/prototype.js +4225 -0
  71. data/test_app/public/robots.txt +5 -0
  72. data/test_app/public/stylesheets/scaffold.css +62 -0
  73. data/test_app/script/about +4 -0
  74. data/test_app/script/console +3 -0
  75. data/test_app/script/dbconsole +3 -0
  76. data/test_app/script/destroy +3 -0
  77. data/test_app/script/generate +3 -0
  78. data/test_app/script/performance/benchmarker +3 -0
  79. data/test_app/script/performance/profiler +3 -0
  80. data/test_app/script/performance/request +3 -0
  81. data/test_app/script/plugin +3 -0
  82. data/test_app/script/process/inspector +3 -0
  83. data/test_app/script/process/reaper +3 -0
  84. data/test_app/script/process/spawner +3 -0
  85. data/test_app/script/runner +3 -0
  86. data/test_app/script/server +3 -0
  87. data/test_app/test/fixtures/companies.yml +7 -0
  88. data/test_app/test/fixtures/projects.yml +4 -0
  89. data/test_app/test/fixtures/users.yml +21 -0
  90. data/test_app/test/functional/companies_controller_test.rb +8 -0
  91. data/test_app/test/functional/user_sessions_controller_test.rb +36 -0
  92. data/test_app/test/functional/users_controller_test.rb +8 -0
  93. data/test_app/test/integration/company_user_session_stories_test.rb +46 -0
  94. data/test_app/test/integration/user_sesion_stories_test.rb +105 -0
  95. data/test_app/test/integration/user_session_config_test.rb +24 -0
  96. data/test_app/test/integration/user_session_test.rb +161 -0
  97. data/test_app/test/test_helper.rb +81 -0
  98. data/test_app/test/unit/account_test.rb +8 -0
  99. data/test_app/test/unit/company_test.rb +8 -0
  100. data/test_app/test/unit/project_test.rb +8 -0
  101. data/test_app/test/unit/user_test.rb +80 -0
  102. metadata +201 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,62 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ p {
16
+ margin: 0 0 15px 0;
17
+ }
18
+
19
+ a { color: #000; }
20
+ a:visited { color: #666; }
21
+ a:hover { color: #fff; background-color:#000; }
22
+
23
+ .fieldWithErrors {
24
+ padding: 2px;
25
+ background-color: red;
26
+ display: inline;
27
+ }
28
+
29
+ .fieldWithErrors label {
30
+ color: white;
31
+ }
32
+
33
+ #errorExplanation {
34
+ width: 400px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 12px;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #errorExplanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ background-color: #c00;
49
+ color: #fff;
50
+ }
51
+
52
+ #errorExplanation p {
53
+ color: #333;
54
+ margin-bottom: 0;
55
+ padding: 5px;
56
+ }
57
+
58
+ #errorExplanation ul li {
59
+ font-size: 12px;
60
+ list-style: square;
61
+ }
62
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/request'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,7 @@
1
+ binary_logic:
2
+ id: 1
3
+ name: Binary Logic
4
+
5
+ logic_over_data:
6
+ id: 2
7
+ name: Logic Over Data
@@ -0,0 +1,4 @@
1
+ web_services:
2
+ id: 1
3
+ name: web services
4
+
@@ -0,0 +1,21 @@
1
+ ben:
2
+ id: 1
3
+ company_id: 1
4
+ projects: web_services
5
+ login: bjohnson
6
+ password_salt: <%= salt = User.unique_token %>
7
+ crypted_password: <%= Authlogic::Sha512CryptoProvider.encrypt("benrocks" + salt) %>
8
+ remember_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317
9
+ first_name: Ben
10
+ last_name: Johnson
11
+
12
+ zack:
13
+ id: 2
14
+ company_id: 2
15
+ projects: web_services
16
+ login: zham
17
+ password_salt: <%= salt = User.unique_token %>
18
+ crypted_password: <%= Authlogic::Sha512CryptoProvider.encrypt("zackrocks" + salt) %>
19
+ remember_token: fd3c2d5ce09ab98e7547d21f1b3dcf9158a9a19b5d3022c0402f32ae197019fce3fdbc6614d7ee57d719bae53bb089e30edc9e5d6153e5bc3afca0ac1d320342
20
+ first_name: Zack
21
+ last_name: Ham
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class CompaniesControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ def test_truth
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ class UserSessionsControllerTest < ActionController::TestCase
4
+ def setup
5
+ @controller = UserSessionsController.new
6
+ @request = ActionController::TestRequest.new
7
+ @response = ActionController::TestResponse.new
8
+ end
9
+
10
+ def test_new
11
+ get :new
12
+ assert @controller.instance_variable_get(:@user_session).is_a?(UserSession)
13
+ end
14
+
15
+ def test_successful_create
16
+ get :create, {:user_session => {:login => "bjohnson", :password => "benrocks"}}
17
+ assert_equal "6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317", session[:user_credentials]
18
+ assert_equal ["6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317"], cookies["user_credentials"]
19
+ assert_redirected_to account_url
20
+ end
21
+
22
+ def test_unsuccessful_create
23
+ get :create, {:user_session => {:login => "bjohnson", :password => "badpassword"}}
24
+ assert_equal nil, session[:user_credentials]
25
+ assert_equal nil, cookies["user_credentials"]
26
+ assert_template "new"
27
+ end
28
+
29
+ def test_destroy
30
+ get :destroy
31
+ assert_equal nil, session[:user_credentials]
32
+ assert_equal nil, cookies["user_credentials"]
33
+ assert_redirected_to new_user_session_url
34
+ assert flash.key?(:notice)
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ def test_truth
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+
3
+ class CompanyUserSessionStoriesTest < ActionController::IntegrationTest
4
+ def setup
5
+ super
6
+ self.scope = Company.first
7
+ end
8
+
9
+ def test_login_process
10
+ # Try to access the company account area without being logged in
11
+ get scoped_url("account_url")
12
+ assert_redirected_to scoped_url("new_user_session_url")
13
+ follow_redirect!
14
+ assert flash.key?(:notice)
15
+ assert_template "user_sessions/new"
16
+
17
+ # Try to login unsuccessfully
18
+ assert_unsuccessful_login
19
+ assert_unsuccessful_login("bjohnson", "badpassword")
20
+ assert_unsuccessful_login("zham", "zackrocks") # this is correct, but zack does not belong to this company
21
+
22
+ assert_successful_login("bjohnson", "benrocks")
23
+
24
+ # Try to log in again after a successful login
25
+ get scoped_url("new_user_session_url")
26
+ assert_redirected_to scoped_url("account_url")
27
+ follow_redirect!
28
+ assert flash.key?(:notice)
29
+ assert_template "users/show"
30
+
31
+ # Try to register after a successful login
32
+ get scoped_url("new_account_url")
33
+ assert_redirected_to scoped_url("account_url")
34
+ follow_redirect!
35
+ assert flash.key?(:notice)
36
+ assert_template "users/show"
37
+
38
+ assert_account_access
39
+ assert_successful_logout(scoped_url("new_account_url")) # before I tried to register, it stored my location
40
+
41
+ # Try to access my account again
42
+ get scoped_url("account_url")
43
+ assert_redirected_to scoped_url("new_user_session_url")
44
+ assert flash.key?(:notice)
45
+ end
46
+ end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ class UserSessionStoriesTest < ActionController::IntegrationTest
4
+ def test_registration
5
+ # Try to access the account area without being logged in
6
+ get account_url
7
+ assert_redirected_to new_user_session_url
8
+ follow_redirect!
9
+ assert flash.key?(:notice)
10
+ assert_template "user_sessions/new"
11
+
12
+ # Try to register with no info
13
+ post account_url
14
+ assert_template "users/new"
15
+
16
+ # Register successfully
17
+ post account_url, {:user => {:login => "binarylogic", :password => "pass", :confirm_password => "pass", :first_name => "Ben", :last_name => "Johnson"}}
18
+ assert_redirected_to account_url
19
+ assert flash.key?(:notice)
20
+
21
+ assert_account_access(User.last)
22
+ end
23
+
24
+ def test_login_process
25
+ # Try to access the account area without being logged in
26
+ get account_url
27
+ assert_redirected_to new_user_session_url
28
+ follow_redirect!
29
+ assert flash.key?(:notice)
30
+ assert_template "user_sessions/new"
31
+
32
+ assert_unsuccessful_login
33
+ assert_unsuccessful_login("bjohnson", "badpassword")
34
+ assert_successful_login("bjohnson", "benrocks")
35
+
36
+ # Try to log in again after a successful login
37
+ get new_user_session_url
38
+ assert_redirected_to account_url
39
+ follow_redirect!
40
+ assert flash.key?(:notice)
41
+ assert_template "users/show"
42
+
43
+ # Try to register after a successful login
44
+ get new_account_url
45
+ assert_redirected_to account_url
46
+ follow_redirect!
47
+ assert flash.key?(:notice)
48
+ assert_template "users/show"
49
+
50
+ assert_account_access
51
+ assert_successful_logout(new_account_url) # before I tried to register, it stored my location
52
+
53
+ # Try to access my account again
54
+ get account_url
55
+ assert_redirected_to new_user_session_url
56
+ assert flash.key?(:notice)
57
+ end
58
+
59
+ def test_changing_password
60
+ # Try logging in with correct credentials
61
+ assert_successful_login("bjohnson", "benrocks")
62
+
63
+ # Go to edit form
64
+ get edit_account_path
65
+ assert_template "users/edit"
66
+
67
+ # Edit password
68
+ put account_path, :user => {:login => "bjohnson", :password => "sillywilly", :confirm_password => "sillywilly", :first_name => "Ben", :last_name => "Johnson"}
69
+ assert_redirected_to account_url
70
+ follow_redirect!
71
+ assert flash.key?(:notice)
72
+ assert_template "users/show"
73
+
74
+ assert_account_access
75
+ assert_successful_logout
76
+
77
+ # Try to access my account again
78
+ get account_url
79
+ assert_redirected_to new_user_session_url
80
+ assert flash.key?(:notice)
81
+
82
+ assert_successful_login("bjohnson", "sillywilly")
83
+ assert_account_access
84
+ end
85
+
86
+ def test_updating_user_with_no_password_change
87
+ ben = users(:ben)
88
+ profile_views = ben.profile_views
89
+ assert_no_account_access
90
+ get user_url(ben)
91
+ ben.reload
92
+ assert ben.profile_views > profile_views
93
+ assert_no_account_access
94
+ end
95
+
96
+ def test_updating_user_with_password_change
97
+ ben = users(:ben)
98
+ crypted_password = ben.crypted_password
99
+ assert_no_account_access
100
+ get reset_password_user_url(ben)
101
+ ben.reload
102
+ assert_not_equal crypted_password, ben.crypted_password
103
+ assert_account_access
104
+ end
105
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class UserSessionConfigTest < ActionController::IntegrationTest
4
+ =begin
5
+ def test_authenticate_with
6
+ UserSession.authenticate_with = Account
7
+ assert_equal Account, UserSession.authenticate_with
8
+
9
+ UserSession.authenticate_with User
10
+ assert_equal User, UserSession.authenticate_with
11
+ end
12
+
13
+ def test_login_field
14
+ UserSession.login_field = :email
15
+ assert :email, UserSession.login_field
16
+
17
+ UserSession.login_field :email2
18
+ assert :email2, UserSession.login_field
19
+
20
+ UserSession.login_field = :login
21
+ assert :login, UserSession.login_field
22
+ end
23
+ =end
24
+ end
@@ -0,0 +1,161 @@
1
+ require 'test_helper'
2
+
3
+ # I know these tests are not really integration tests, but since UserSessions deals with cookies, models, etc. It was easiest and best to test it via an integration.
4
+ class UserSessionTest < ActionController::IntegrationTest
5
+ def test_activated
6
+ UserSession.controller = nil
7
+ assert !UserSession.activated?
8
+ get new_user_session_url # reactive
9
+ assert UserSession.activated?
10
+ end
11
+
12
+ def test_create
13
+ assert !UserSession.create("unknown", "bad")
14
+ assert UserSession.create("bjohnson", "benrocks")
15
+ assert_raise(Authlogic::Session::SessionInvalid) { assert !UserSession.create!("unknown", "bad") }
16
+ assert_nothing_raised { UserSession.create!("bjohnson", "benrocks") }
17
+ end
18
+
19
+ def test_klass
20
+ assert_equal User, UserSession.klass
21
+ end
22
+
23
+ def test_klass_name
24
+ assert_equal "User", UserSession.klass_name
25
+ end
26
+
27
+ def test_find
28
+ assert_equal nil, UserSession.find
29
+ assert_successful_login("bjohnson", "benrocks")
30
+ assert UserSession.find
31
+ end
32
+
33
+ def test_initialize
34
+ session = UserSession.new
35
+ assert !session.valid?
36
+ assert_equal nil, session.login
37
+ assert_equal nil, session.unauthorized_record
38
+
39
+ session = UserSession.new(:secure)
40
+ assert_equal :secure, session.id
41
+ assert !session.valid?
42
+ assert_equal nil, session.login
43
+ assert_equal nil, session.unauthorized_record
44
+
45
+ session = UserSession.new("user", "pass")
46
+ assert_equal nil, session.id
47
+ assert !session.valid?
48
+ assert_equal "user", session.login
49
+ assert_equal nil, session.unauthorized_record
50
+
51
+ session = UserSession.new("user", "pass", :secure)
52
+ assert_equal :secure, session.id
53
+ assert !session.valid?
54
+ assert_equal "user", session.login
55
+ assert_equal nil, session.unauthorized_record
56
+
57
+ session = UserSession.new(:login => "user", :password => "pass")
58
+ assert_equal nil, session.id
59
+ assert !session.valid?
60
+ assert_equal "user", session.login
61
+ assert_equal nil, session.unauthorized_record
62
+
63
+ session = UserSession.new({:login => "user", :password => "pass"}, :secure)
64
+ assert_equal :secure, session.id
65
+ assert !session.valid?
66
+ assert_equal "user", session.login
67
+ assert_equal nil, session.unauthorized_record
68
+
69
+ session = UserSession.new(users(:ben))
70
+ assert_equal nil, session.id
71
+ assert session.valid?
72
+ assert_equal nil, session.login
73
+ assert_equal users(:ben), session.unauthorized_record
74
+
75
+ session = UserSession.new(users(:ben), :secure)
76
+ assert_equal :secure, session.id
77
+ assert session.valid?
78
+ assert_equal nil, session.login
79
+ assert_equal users(:ben), session.unauthorized_record
80
+ end
81
+
82
+ def test_credentials
83
+ session = UserSession.new
84
+ session.credentials = nil
85
+ assert_equal({:login => nil, :password => "<Protected>"}, session.credentials)
86
+
87
+ session = UserSession.new
88
+ session.credentials = {:login => "ben"}
89
+ assert_equal({:login => "ben", :password => "<Protected>"}, session.credentials)
90
+
91
+ session = UserSession.new
92
+ assert_nothing_raised { session.credentials = {:login => "ben", :random_field => "test"} }
93
+
94
+ session = UserSession.new
95
+ session.credentials = {:login => "ben", :password => "awesome"}
96
+ assert_equal({:login => "ben", :password => "<Protected>"}, session.credentials)
97
+ assert_equal "awesome", session.send(:protected_password)
98
+ end
99
+
100
+ def test_destroy
101
+ # tested thoroughly in stories
102
+ end
103
+
104
+ def test_errors
105
+ # don't need to go crazy here since we are using ActiveRecord's error class, which has been thorough tested there
106
+ session = UserSession.new
107
+ assert !session.valid?
108
+ session.login = ""
109
+ session.password = ""
110
+ assert !session.valid?
111
+ assert session.errors.on(:login)
112
+ assert session.errors.on(:password)
113
+ end
114
+
115
+ def test_id
116
+ session = UserSession.new
117
+ assert_equal nil, session.id
118
+ session.id = :secure
119
+ assert_equal :secure, session.id
120
+ end
121
+
122
+ def test_inspect
123
+ session = UserSession.new
124
+ assert_equal "#<UserSession {:login=>nil, :password=>\"<protected>\"}>", session.inspect
125
+
126
+ session = UserSession.new("user", "pass")
127
+ assert_equal "#<UserSession {:login=>\"user\", :password=>\"<protected>\"}>", session.inspect
128
+
129
+ session = UserSession.new(users(:ben))
130
+ assert_equal "#<UserSession {:unauthorized_record=>\"<protected>\"}>", session.inspect
131
+ end
132
+
133
+ def test_new_session
134
+ session = UserSession.new
135
+ assert session.new_session?
136
+
137
+ session.login = "bjohnson"
138
+ session.password = "benrocks"
139
+ session.save
140
+ assert !session.new_session?
141
+
142
+ assert_successful_login("bjohnson", "benrocks")
143
+ session = UserSession.find
144
+ assert !session.new_session?
145
+ end
146
+
147
+ def test_remember_me
148
+ session = UserSession.new
149
+ session.remember_me = true
150
+ assert_equal 3.months, session.remember_me_for
151
+ assert session.remember_me_until > Time.now
152
+
153
+ session.remember_me = false
154
+ assert_equal nil, session.remember_me_for
155
+ assert_equal nil, session.remember_me_until
156
+ end
157
+
158
+ def test_save
159
+ # tested thoroughly in stories and in create above
160
+ end
161
+ end