Permalink
Browse files

[#42 state:resolved] Rack-based session change altered how to test re…

…member me cookie. Hat-tip Mihai Anca.
  • Loading branch information...
1 parent 90dbd00 commit 0f97c7e75b8a63ec99d06391ebae3b6e0fb20a18 @croaky croaky committed Feb 27, 2009
Showing with 34 additions and 25 deletions.
  1. +5 −0 CHANGELOG.textile
  2. +29 −25 lib/clearance/test/functional/sessions_controller_test.rb
View
@@ -4,6 +4,11 @@ h1. 0.5.1 (not yet released)
(Marcel Görner)
* Refactored user_from_cookie, user_from_session, User#authenticate to use
more direct return code instead of ugly, harder to read ternary. (Dan Croak)
+* Switch order of cookies and sessions to take advantage of Rails 2.3's "Rack-based lazy-loaded sessions":http://is.gd/i23E. (Dan Croak)
+* Altered generator to interact with application_controller.rb instead of
+application.rb in Rails 2.3 apps. (Dan Croak)
+* [#42] Bug fix. Rack-based session change altered how to test remember me
+cookie. (Mihai Anca)
h2. 0.5.0 (2/27/2009)
@@ -2,19 +2,18 @@ module Clearance
module Test
module Functional
module SessionsControllerTest
-
+
def self.included(controller_test)
controller_test.class_eval do
-
+
should_filter_params :password
context "on GET to /sessions/new" do
setup { get :new }
-
+
should_respond_with :success
should_render_template :new
should_not_set_the_flash
-
should_display_a_sign_in_form
end
@@ -42,7 +41,7 @@ def self.included(controller_test)
context "Given an email confirmed user" do
setup do
@user = Factory(:user)
- @user.confirm_email!
+ @user.confirm_email!
end
context "a POST to #create with good credentials" do
@@ -69,7 +68,7 @@ def self.included(controller_test)
should_render_template :new
should_not_be_signed_in
end
-
+
context "a POST to #create with good credentials and remember me" do
setup do
post :create, :session => {
@@ -81,7 +80,7 @@ def self.included(controller_test)
should_set_the_flash_to /success/i
should_redirect_to_url_after_create
should_be_signed_in_as { @user }
-
+
should 'set the cookie' do
assert ! cookies['remember_token'].empty?
end
@@ -91,7 +90,7 @@ def self.included(controller_test)
assert_not_nil @user.reload.token_expires_at
end
end
-
+
context "a POST to #create with bad credentials and remember me" do
setup do
post :create, :session => {
@@ -104,7 +103,7 @@ def self.included(controller_test)
should_respond_with :unauthorized
should_render_template :new
should_return_from_session :user_id, "nil"
-
+
should 'not create the cookie' do
assert_nil cookies['remember_token']
end
@@ -114,42 +113,42 @@ def self.included(controller_test)
assert_nil @user.reload.token_expires_at
end
end
-
+
context "a POST to #create with good credentials and A URL to return back" do
context "in the session" do
setup do
@request.session[:return_to] = '/url_in_the_session'
- post :create, :session => {
- :email => @user.email,
- :password => @user.password }
+ post :create, :session => {
+ :email => @user.email,
+ :password => @user.password }
end
-
+
should_redirect_to "'/url_in_the_session'"
end
-
+
context "in the request" do
setup do
post :create, :session => {
:email => @user.email,
:password => @user.password },
- :return_to => '/url_in_the_request'
+ :return_to => '/url_in_the_request'
end
-
+
should_redirect_to "'/url_in_the_request'"
- end
-
+ end
+
context "in the request and in the session" do
setup do
@request.session[:return_to] = '/url_in_the_session'
post :create, :session => {
:email => @user.email,
:password => @user.password },
- :return_to => '/url_in_the_request'
+ :return_to => '/url_in_the_request'
end
-
+
should_redirect_to "'/url_in_the_session'"
end
- end
+ end
end
public_context do
@@ -169,12 +168,17 @@ def self.included(controller_test)
context 'a DELETE to #destroy with a cookie' do
setup do
- cookies['remember_token'] = CGI::Cookie.new('token', 'value')
+ @request.cookies['remember_token'] = {
@ropiku

ropiku Mar 1, 2009

On Rails 2.3 and edge it fails with “ArgumentError: Unknown key(s): value, name”. Any ideas ?

+ :name => 'token',
+ :value => 'value'
+ }
+ @controller.request = @request
delete :destroy
end
should 'delete the cookie' do
- assert cookies['remember_token'].empty?
+ assert cookies['remember_token'].nil? || # Rails >= 2.3
+ cookies['remember_token'].empty? # Rails < 2.3
end
should 'delete the remember me token in users table' do
@@ -183,7 +187,7 @@ def self.included(controller_test)
end
end
end
-
+
end
end

2 comments on commit 0f97c7e

Owner

croaky replied Mar 2, 2009

@ropiku I’ve just pushed a change. Should be fixed in 0.5.2.

@dancroak: Perfect, thanks :)

Please sign in to comment.