clearance 0.8.8 → 0.9.0.rc1

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

Potentially problematic release.


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

Files changed (94) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/README.md +27 -32
  3. data/Rakefile +25 -31
  4. data/app/controllers/clearance/passwords_controller.rb +1 -1
  5. data/app/controllers/clearance/sessions_controller.rb +1 -1
  6. data/app/models/clearance_mailer.rb +4 -4
  7. data/app/views/passwords/edit.html.erb +1 -1
  8. data/app/views/passwords/new.html.erb +2 -2
  9. data/app/views/sessions/new.html.erb +1 -1
  10. data/app/views/users/_form.html.erb +1 -1
  11. data/app/views/users/new.html.erb +1 -1
  12. data/config/routes.rb +30 -0
  13. data/lib/clearance.rb +2 -1
  14. data/lib/clearance/authentication.rb +2 -2
  15. data/lib/clearance/configuration.rb +10 -3
  16. data/lib/clearance/engine.rb +8 -0
  17. data/lib/clearance/user.rb +5 -6
  18. data/lib/rails/generators/clearance_features_generator.rb +20 -0
  19. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/password_reset.feature +1 -1
  20. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_in.feature +0 -0
  21. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_out.feature +0 -0
  22. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_up.feature +0 -0
  23. data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/step_definitions/clearance_steps.rb +13 -5
  24. data/lib/rails/generators/clearance_generator.rb +68 -0
  25. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/README +0 -0
  26. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/clearance.rb +0 -0
  27. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/factories.rb +0 -0
  28. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/create_users.rb +0 -1
  29. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/update_users.rb +0 -1
  30. data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/user.rb +0 -0
  31. data/lib/rails/generators/clearance_views_generator.rb +14 -0
  32. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/edit.html.erb +3 -3
  33. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/new.html.erb +3 -3
  34. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/sessions/new.html.erb +3 -3
  35. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/_inputs.html.erb +1 -1
  36. data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/new.html.erb +2 -2
  37. data/shoulda_macros/clearance.rb +9 -17
  38. data/test/controllers/confirmations_controller_test.rb +6 -6
  39. data/test/controllers/passwords_controller_test.rb +10 -10
  40. data/test/controllers/sessions_controller_test.rb +57 -16
  41. data/test/controllers/users_controller_test.rb +12 -8
  42. data/test/models/clearance_mailer_test.rb +2 -2
  43. data/test/models/user_test.rb +14 -7
  44. data/test/rails_root/app/helpers/application_helper.rb +0 -3
  45. data/test/rails_root/config/application.rb +46 -0
  46. data/test/rails_root/config/boot.rb +5 -109
  47. data/test/rails_root/config/environment.rb +5 -15
  48. data/test/rails_root/config/environments/development.rb +15 -15
  49. data/test/rails_root/config/environments/production.rb +42 -1
  50. data/test/rails_root/config/environments/test.rb +25 -29
  51. data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/rails_root/config/initializers/inflections.rb +1 -1
  53. data/test/rails_root/config/initializers/secret_token.rb +7 -0
  54. data/test/rails_root/config/initializers/session_store.rb +8 -0
  55. data/test/rails_root/config/routes.rb +57 -2
  56. data/test/rails_root/features/step_definitions/web_steps.rb +125 -165
  57. data/test/rails_root/features/support/env.rb +24 -14
  58. data/test/rails_root/features/support/paths.rb +26 -4
  59. data/test/rails_root/test/functional/accounts_controller_test.rb +0 -1
  60. data/test/rails_root/test/performance/browsing_test.rb +9 -0
  61. data/test/rails_root/test/test_helper.rb +13 -0
  62. data/test/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
  63. data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
  64. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
  65. data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
  66. data/test/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
  67. data/test/test_helper.rb +30 -1
  68. metadata +104 -49
  69. data/VERSION +0 -1
  70. data/generators/clearance/USAGE +0 -1
  71. data/generators/clearance/clearance_generator.rb +0 -68
  72. data/generators/clearance/lib/insert_commands.rb +0 -33
  73. data/generators/clearance/lib/rake_commands.rb +0 -22
  74. data/generators/clearance_features/USAGE +0 -1
  75. data/generators/clearance_features/clearance_features_generator.rb +0 -19
  76. data/generators/clearance_features/templates/features/support/paths.rb +0 -23
  77. data/generators/clearance_views/USAGE +0 -0
  78. data/generators/clearance_views/clearance_views_generator.rb +0 -27
  79. data/lib/clearance/routes.rb +0 -49
  80. data/test/rails_root/app/helpers/confirmations_helper.rb +0 -2
  81. data/test/rails_root/app/helpers/passwords_helper.rb +0 -2
  82. data/test/rails_root/config/initializers/requires.rb +0 -13
  83. data/test/rails_root/config/initializers/time_formats.rb +0 -4
  84. data/test/rails_root/db/migrate/20100225210436_clearance_create_users.rb +0 -21
  85. data/test/rails_root/features/step_definitions/clearance_steps.rb +0 -122
  86. data/test/rails_root/features/step_definitions/factory_girl_steps.rb +0 -5
  87. data/test/rails_root/public/dispatch.rb +0 -10
  88. data/test/rails_root/script/create_project.rb +0 -52
  89. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +0 -21
  90. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +0 -1236
  91. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +0 -10
  92. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +0 -3
  93. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +0 -2900
  94. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +0 -14
@@ -0,0 +1,20 @@
1
+ class ClearanceFeaturesGenerator < Rails::Generators::Base
2
+ desc "Put the clearance features in place"
3
+
4
+ def self.source_root
5
+ @_clearance_source_root ||= File.join(File.dirname(__FILE__), "clearance_features_templates")
6
+ end
7
+
8
+ def install
9
+ directory "features"
10
+
11
+ inject_into_file "features/support/paths.rb", :after => "# Add more mappings here.\n" do
12
+ " when /the sign up page/i
13
+ sign_up_path
14
+ when /the sign in page/i
15
+ sign_in_path
16
+ when /the password reset request page/i
17
+ new_password_path\n"
18
+ end
19
+ end
20
+ end
@@ -18,7 +18,7 @@ Feature: Password reset
18
18
  Given I signed up with "email@person.com/password"
19
19
  When I follow the password reset link sent to "email@person.com"
20
20
  And I update my password with "newpassword/wrongconfirmation"
21
- Then I should see error messages
21
+ Then I should see an error message
22
22
  And I should be signed out
23
23
 
24
24
  Scenario: User is signed up and updates his password
@@ -1,7 +1,11 @@
1
1
  # General
2
2
 
3
3
  Then /^I should see error messages$/ do
4
- assert_match /error(s)? prohibited/m, response.body
4
+ Then %{I should see "errors prohibited"}
5
+ end
6
+
7
+ Then /^I should see an error message$/ do
8
+ Then %{I should see "error prohibited"}
5
9
  end
6
10
 
7
11
  # Database
@@ -27,16 +31,20 @@ end
27
31
  # Session
28
32
 
29
33
  Then /^I should be signed in$/ do
30
- assert controller.signed_in?
34
+ Given %{I am on the homepage}
35
+ Then %{I should see "Sign out"}
31
36
  end
32
37
 
33
38
  Then /^I should be signed out$/ do
34
- assert ! controller.signed_in?
39
+ Given %{I am on the homepage}
40
+ Then %{I should see "Sign in"}
35
41
  end
36
42
 
37
43
  When /^session is cleared$/ do
38
- request.reset_session
39
- controller.instance_variable_set(:@_current_user, nil)
44
+ # TODO: This doesn't work with Capybara
45
+ # TODO: I tried Capybara.reset_sessions! but that didn't work
46
+ #request.reset_session
47
+ #controller.instance_variable_set(:@_current_user, nil)
40
48
  end
41
49
 
42
50
  Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
@@ -0,0 +1,68 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class ClearanceGenerator < ActiveRecord::Generators::Base
4
+ desc "Setup the basic stuff needed for Clearance"
5
+
6
+ argument :name, :type => :string, :default => "migration_source_name"
7
+
8
+ def self.source_root
9
+ @_clearance_source_root ||= File.join(File.dirname(__FILE__), "clearance_templates")
10
+ end
11
+
12
+ def install
13
+ template "clearance.rb", "config/initializers/clearance.rb"
14
+
15
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController do
16
+ " include Clearance::Authentication\n"
17
+ end
18
+
19
+ user_model = "app/models/user.rb"
20
+ if File.exists?(user_model)
21
+ inject_into_class user_model, User do
22
+ "include Clearance::User"
23
+ end
24
+ else
25
+ template "user.rb", user_model
26
+ end
27
+
28
+ template "factories.rb", "test/factories/clearance.rb"
29
+
30
+ migration_template "migrations/#{migration_source_name}.rb",
31
+ "db/migrate/clearance_#{migration_target_name}"
32
+
33
+ #readme "README"
34
+ end
35
+
36
+ private
37
+
38
+ def schema_version_constant
39
+ if upgrading_clearance_again?
40
+ "To#{schema_version.gsub('_', '')}"
41
+ end
42
+ end
43
+
44
+ def migration_source_name
45
+ if ActiveRecord::Base.connection.table_exists?(:users)
46
+ 'update_users'
47
+ else
48
+ 'create_users'
49
+ end
50
+ end
51
+
52
+ def migration_target_name
53
+ if upgrading_clearance_again?
54
+ "update_users_to_#{schema_version}"
55
+ else
56
+ 'create_users'
57
+ end
58
+ end
59
+
60
+ def schema_version
61
+ IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_')
62
+ end
63
+
64
+ def upgrading_clearance_again?
65
+ ActiveRecord::Base.connection.table_exists?(:users)
66
+ end
67
+
68
+ end
@@ -10,7 +10,6 @@ class ClearanceCreateUsers < ActiveRecord::Migration
10
10
  t.timestamps
11
11
  end
12
12
 
13
- add_index :users, [:id, :confirmation_token]
14
13
  add_index :users, :email
15
14
  add_index :users, :remember_token
16
15
  end
@@ -21,7 +21,6 @@ class ClearanceUpdateUsers<%= schema_version_constant %> < ActiveRecord::Migrati
21
21
  existing_indexes = ActiveRecord::Base.connection.indexes(:users)
22
22
  index_names = existing_indexes.collect { |each| each.name }
23
23
  new_indexes = [
24
- [:index_users_on_id_and_confirmation_token, 'add_index :users, [:id, :confirmation_token]'],
25
24
  [:index_users_on_email, 'add_index :users, :email'],
26
25
  [:index_users_on_remember_token, 'add_index :users, :remember_token']
27
26
  ].delete_if { |each| index_names.include?(each.first.to_s) }
@@ -0,0 +1,14 @@
1
+ class ClearanceViewsGenerator < Rails::Generators::Base
2
+ desc "Put the clearance views in place"
3
+
4
+ def self.source_root
5
+ @_clearance_source_root ||= File.join(File.dirname(__FILE__), "clearance_views_templates")
6
+ end
7
+
8
+ def install
9
+ strategy = "formtastic"
10
+ template_strategy = "erb"
11
+
12
+ directory "#{strategy}/#{template_strategy}", "app/views"
13
+ end
14
+ end
@@ -4,17 +4,17 @@
4
4
  Your password has been reset. Choose a new password below.
5
5
  </p>
6
6
 
7
- <% semantic_form_for(:user,
7
+ <%= semantic_form_for(:user,
8
8
  :url => user_password_path(@user, :token => @user.confirmation_token),
9
9
  :html => { :method => :put }) do |form| %>
10
10
  <%= form.error_messages %>
11
- <% form.inputs do -%>
11
+ <%= form.inputs do -%>
12
12
  <%= form.input :password, :as => :password,
13
13
  :label => "Choose password" %>
14
14
  <%= form.input :password_confirmation, :as => :password,
15
15
  :label => "Confirm password" %>
16
16
  <% end -%>
17
- <% form.buttons do -%>
17
+ <%= form.buttons do -%>
18
18
  <%= form.commit_button "Save this password" %>
19
19
  <% end -%>
20
20
  <% end %>
@@ -4,11 +4,11 @@
4
4
  We will email you a link to reset your password.
5
5
  </p>
6
6
 
7
- <% semantic_form_for :password, :url => passwords_path do |form| -%>
8
- <% form.inputs do -%>
7
+ <%= semantic_form_for :password, :url => passwords_path do |form| -%>
8
+ <%= form.inputs do -%>
9
9
  <%= form.input :email, :label => "Email address" %>
10
10
  <% end -%>
11
- <% form.buttons do -%>
11
+ <%= form.buttons do -%>
12
12
  <%= form.commit_button "Reset password" %>
13
13
  <% end -%>
14
14
  <% end -%>
@@ -1,11 +1,11 @@
1
1
  <h2>Sign in</h2>
2
2
 
3
- <% semantic_form_for :session, :url => session_path do |form| %>
4
- <% form.inputs do %>
3
+ <%= semantic_form_for :session, :url => session_path do |form| %>
4
+ <%= form.inputs do %>
5
5
  <%= form.input :email %>
6
6
  <%= form.input :password, :as => :password %>
7
7
  <% end %>
8
- <% form.buttons do %>
8
+ <%= form.buttons do %>
9
9
  <%= form.commit_button "Sign in" %>
10
10
  <% end %>
11
11
  <% end %>
@@ -1,4 +1,4 @@
1
- <% form.inputs do %>
1
+ <%= form.inputs do %>
2
2
  <%= form.input :email %>
3
3
  <%= form.input :password %>
4
4
  <%= form.input :password_confirmation, :label => "Confirm password" %>
@@ -1,9 +1,9 @@
1
1
  <h2>Sign up</h2>
2
2
 
3
- <% semantic_form_for @user do |form| %>
3
+ <%= semantic_form_for @user do |form| %>
4
4
  <%= form.error_messages %>
5
5
  <%= render :partial => "/users/inputs", :locals => { :form => form } %>
6
- <% form.buttons do %>
6
+ <%= form.buttons do %>
7
7
  <%= form.commit_button "Sign up" %>
8
8
  <% end %>
9
9
  <% end %>
@@ -49,12 +49,12 @@ module Clearance
49
49
 
50
50
  def should_deny_access(opts = {})
51
51
  if opts[:flash]
52
- should_set_the_flash_to opts[:flash]
52
+ should set_the_flash.to(opts[:flash])
53
53
  else
54
- should_not_set_the_flash
54
+ should_not set_the_flash
55
55
  end
56
56
 
57
- should_redirect_to('sign in page') { sign_in_url }
57
+ should redirect_to('sign in page') { sign_in_url }
58
58
  end
59
59
 
60
60
  # HTTP FLUENCY
@@ -102,7 +102,7 @@ module Clearance
102
102
  end
103
103
  end
104
104
 
105
- should_set_the_flash_to /confirm/i
105
+ should set_the_flash.to(/confirm/i)
106
106
  should_redirect_to_url_after_create
107
107
  end
108
108
 
@@ -117,27 +117,19 @@ module Clearance
117
117
  # REDIRECTS
118
118
 
119
119
  def should_redirect_to_url_after_create
120
- should_redirect_to("the post-create url") do
121
- @controller.send(:url_after_create)
122
- end
120
+ should redirect_to("the post-create url") { @controller.send(:url_after_create) }
123
121
  end
124
122
 
125
123
  def should_redirect_to_url_after_update
126
- should_redirect_to("the post-update url") do
127
- @controller.send(:url_after_update)
128
- end
124
+ should redirect_to("the post-update url") { @controller.send(:url_after_update) }
129
125
  end
130
126
 
131
127
  def should_redirect_to_url_after_destroy
132
- should_redirect_to("the post-destroy url") do
133
- @controller.send(:url_after_destroy)
134
- end
128
+ should redirect_to("the post-destroy url") { @controller.send(:url_after_destroy) }
135
129
  end
136
130
 
137
131
  def should_redirect_to_url_already_confirmed
138
- should_redirect_to("the already confirmed url") do
139
- @controller.send(:url_already_confirmed)
140
- end
132
+ should redirect_to("the already confirmed url") { @controller.send(:url_already_confirmed) }
141
133
  end
142
134
 
143
135
  # VALIDATIONS
@@ -253,7 +245,7 @@ module Clearance
253
245
 
254
246
  def assert_confirmation_error(model, attribute, message = "confirmation error")
255
247
  warn "[DEPRECATION] assert_confirmation_error: not meant to be public, no longer used internally"
256
- assert model.errors.on(attribute).include?("doesn't match confirmation"),
248
+ assert model.errors[attribute].include?("doesn't match confirmation"),
257
249
  message
258
250
  end
259
251
  end
@@ -4,7 +4,7 @@ class ConfirmationsControllerTest < ActionController::TestCase
4
4
 
5
5
  tests Clearance::ConfirmationsController
6
6
 
7
- should_filter_params :token
7
+ should filter_param(:token)
8
8
 
9
9
  context "a user whose email has not been confirmed" do
10
10
  setup { @user = Factory(:user) }
@@ -20,8 +20,8 @@ class ConfirmationsControllerTest < ActionController::TestCase
20
20
  :token => @user.confirmation_token
21
21
  end
22
22
 
23
- should_set_the_flash_to /confirmed email/i
24
- should_set_the_flash_to /signed in/i
23
+ should set_the_flash.to(/confirmed email/i)
24
+ should set_the_flash.to(/signed in/i)
25
25
  should_redirect_to_url_after_create
26
26
 
27
27
  should "set the current user" do
@@ -60,7 +60,7 @@ class ConfirmationsControllerTest < ActionController::TestCase
60
60
  get :new, :user_id => @user.to_param, :token => @token
61
61
  end
62
62
 
63
- should_set_the_flash_to /confirmed email/i
63
+ should set_the_flash.to(/confirmed email/i)
64
64
  should_redirect_to_url_after_create
65
65
  end
66
66
 
@@ -87,8 +87,8 @@ class ConfirmationsControllerTest < ActionController::TestCase
87
87
  get :new, :user_id => @user.to_param, :token => @token
88
88
  end
89
89
 
90
- should_set_the_flash_to /already confirmed/i
91
- should_set_the_flash_to /sign in/i
90
+ should set_the_flash.to(/already confirmed/i)
91
+ should set_the_flash.to(/sign in/i)
92
92
  should_not_be_signed_in
93
93
  should_redirect_to_url_already_confirmed
94
94
  end
@@ -15,8 +15,8 @@ class PasswordsControllerTest < ActionController::TestCase
15
15
  context "on GET to #new" do
16
16
  setup { get :new, :user_id => @user.to_param }
17
17
 
18
- should_respond_with :success
19
- should_render_template "new"
18
+ should respond_with(:success)
19
+ should render_template(:new)
20
20
  end
21
21
 
22
22
  context "on POST to #create" do
@@ -36,7 +36,7 @@ class PasswordsControllerTest < ActionController::TestCase
36
36
  end
37
37
  end
38
38
 
39
- should_set_the_flash_to /password/i
39
+ should set_the_flash.to(/password/i)
40
40
  should_redirect_to_url_after_create
41
41
  end
42
42
 
@@ -64,7 +64,7 @@ class PasswordsControllerTest < ActionController::TestCase
64
64
  assert_match /unknown email/i, flash.now[:failure]
65
65
  end
66
66
 
67
- should_render_template :new
67
+ should render_template(:new)
68
68
  end
69
69
  end
70
70
  end
@@ -85,8 +85,8 @@ class PasswordsControllerTest < ActionController::TestCase
85
85
  assert_equal @user, assigns(:user)
86
86
  end
87
87
 
88
- should_respond_with :success
89
- should_render_template "edit"
88
+ should respond_with(:success)
89
+ should render_template(:edit)
90
90
  should_display_a_password_update_form
91
91
  end
92
92
 
@@ -127,7 +127,7 @@ class PasswordsControllerTest < ActionController::TestCase
127
127
  assert_not_nil @user.remember_token
128
128
  end
129
129
 
130
- should_set_the_flash_to(/signed in/i)
130
+ should set_the_flash.to(/signed in/i)
131
131
  should_redirect_to_url_after_update
132
132
  end
133
133
 
@@ -156,9 +156,9 @@ class PasswordsControllerTest < ActionController::TestCase
156
156
  end
157
157
 
158
158
  should_not_be_signed_in
159
- should_not_set_the_flash
160
- should_respond_with :success
161
- should_render_template :edit
159
+ should_not set_the_flash
160
+ should respond_with(:success)
161
+ should render_template(:edit)
162
162
 
163
163
  should_display_a_password_update_form
164
164
  end
@@ -1,17 +1,16 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SessionsControllerTest < ActionController::TestCase
4
-
5
4
  tests Clearance::SessionsController
6
5
 
7
- should_filter_params :password
6
+ should filter_param(:password)
8
7
 
9
8
  context "on GET to /sessions/new" do
10
9
  setup { get :new }
11
10
 
12
- should_respond_with :success
13
- should_render_template :new
14
- should_not_set_the_flash
11
+ should respond_with(:success)
12
+ should render_template(:new)
13
+ should_not set_the_flash
15
14
  should_display_a_sign_in_form
16
15
  end
17
16
 
@@ -41,11 +40,13 @@ class SessionsControllerTest < ActionController::TestCase
41
40
  :password => @user.password }
42
41
  end
43
42
 
44
- should_set_the_flash_to /signed in/i
43
+ should set_the_flash.to(/signed in/i)
45
44
  should_redirect_to_url_after_create
46
45
 
47
- should 'set the cookie' do
48
- assert ! cookies['remember_token'].empty?
46
+ should_set_cookie("remember_token", "old-token", Clearance.configuration.cookie_expiration.call)
47
+
48
+ should "have a default of 1 year from now" do
49
+ assert_in_delta Clearance.configuration.cookie_expiration.call, 1.year.from_now, 100
49
50
  end
50
51
 
51
52
  should "not change the remember token" do
@@ -53,6 +54,46 @@ class SessionsControllerTest < ActionController::TestCase
53
54
  end
54
55
  end
55
56
 
57
+ context "on POST to #create with good credentials - cookie duration set to 2 weeks" do
58
+ custom_duration = 2.weeks.from_now.utc
59
+
60
+ setup do
61
+ Clearance.configuration.cookie_expiration = lambda { custom_duration }
62
+ @user = Factory(:email_confirmed_user)
63
+ @user.update_attribute(:remember_token, "old-token2")
64
+ post :create, :session => {
65
+ :email => @user.email,
66
+ :password => @user.password }
67
+ end
68
+
69
+ should_set_cookie("remember_token", "old-token2", custom_duration)
70
+
71
+ teardown do
72
+ # restore default Clearance configuration
73
+ Clearance.configuration = nil
74
+ Clearance.configure {}
75
+ end
76
+ end
77
+
78
+ context "on POST to #create with good credentials - cookie expiration set to nil (session cookie)" do
79
+ setup do
80
+ Clearance.configuration.cookie_expiration = lambda { nil }
81
+ @user = Factory(:email_confirmed_user)
82
+ @user.update_attribute(:remember_token, "old-token3")
83
+ post :create, :session => {
84
+ :email => @user.email,
85
+ :password => @user.password }
86
+ end
87
+
88
+ should_set_cookie("remember_token", "old-token3", nil)
89
+
90
+ teardown do
91
+ # restore default Clearance configuration
92
+ Clearance.configuration = nil
93
+ Clearance.configure {}
94
+ end
95
+ end
96
+
56
97
  context "on POST to #create with good credentials and a session return url" do
57
98
  setup do
58
99
  @user = Factory(:email_confirmed_user)
@@ -63,7 +104,7 @@ class SessionsControllerTest < ActionController::TestCase
63
104
  :password => @user.password }
64
105
  end
65
106
 
66
- should_redirect_to("the return URL") { @return_url }
107
+ should redirect_to("the return URL") { @return_url }
67
108
  end
68
109
 
69
110
  context "on POST to #create with good credentials and a request return url" do
@@ -76,7 +117,7 @@ class SessionsControllerTest < ActionController::TestCase
76
117
  :return_to => @return_url
77
118
  end
78
119
 
79
- should_redirect_to("the return URL") { @return_url }
120
+ should redirect_to("the return URL") { @return_url }
80
121
  end
81
122
 
82
123
  context "on POST to #create with good credentials and a session return url and request return url" do
@@ -90,7 +131,7 @@ class SessionsControllerTest < ActionController::TestCase
90
131
  :return_to => '/url_in_the_request'
91
132
  end
92
133
 
93
- should_redirect_to("the return URL") { @return_url }
134
+ should redirect_to("the return URL") { @return_url }
94
135
  end
95
136
 
96
137
  context "on POST to #create with bad credentials" do
@@ -100,9 +141,9 @@ class SessionsControllerTest < ActionController::TestCase
100
141
  :password => "bad value" }
101
142
  end
102
143
 
103
- should_set_the_flash_to /bad/i
104
- should_respond_with :unauthorized
105
- should_render_template :new
144
+ should set_the_flash.to(/bad/i)
145
+ should respond_with(:unauthorized)
146
+ should render_template(:new)
106
147
  should_not_be_signed_in
107
148
 
108
149
  should 'not create the cookie' do
@@ -115,7 +156,7 @@ class SessionsControllerTest < ActionController::TestCase
115
156
  sign_out
116
157
  delete :destroy
117
158
  end
118
- should_set_the_flash_to(/signed out/i)
159
+ should set_the_flash.to(/signed out/i)
119
160
  should_redirect_to_url_after_destroy
120
161
  end
121
162
 
@@ -127,7 +168,7 @@ class SessionsControllerTest < ActionController::TestCase
127
168
  delete :destroy
128
169
  end
129
170
 
130
- should_set_the_flash_to(/signed out/i)
171
+ should set_the_flash.to(/signed out/i)
131
172
  should_redirect_to_url_after_destroy
132
173
 
133
174
  should "delete the cookie token" do