diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 759344ad..41e23172 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,6 @@ +* bug fix + * Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts; + == 1.1.rc2 * enhancements @@ -16,7 +19,7 @@ * devise.mailer.user.confirmations_instructions now should be devise.mailer.confirmations_instructions.user_subject * Generators now use Rails 3 syntax (devise:install) instead of devise_install -== 1.1.rc +== 1.1.rc1 * enhancements * Rails 3 compatibility diff --git a/lib/devise/test_helpers.rb b/lib/devise/test_helpers.rb index 0d051a1d..a17b906e 100644 --- a/lib/devise/test_helpers.rb +++ b/lib/devise/test_helpers.rb @@ -42,6 +42,8 @@ module Devise status, headers, body = Devise::FailureApp.call(env).to_a @controller.send :render, :status => status, :text => body, :content_type => headers["Content-Type"], :location => headers["Location"] + + nil else result end diff --git a/test/rails_app/app/controllers/users_controller.rb b/test/rails_app/app/controllers/users_controller.rb index 15954419..26076fb7 100644 --- a/test/rails_app/app/controllers/users_controller.rb +++ b/test/rails_app/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ class UsersController < ApplicationController - before_filter :authenticate_user! + before_filter :authenticate_user!, :except => :show respond_to :html, :xml def index @@ -7,6 +7,10 @@ class UsersController < ApplicationController respond_with(current_user) end + def show + @current_user = current_user + end + def expire user_session['last_request_at'] = 31.minutes.ago.utc render :text => 'User will be expired on next request' diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index 74f6d832..6687e38f 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -1,5 +1,5 @@ Rails::Application.routes.draw do - resources :users, :only => [:index] do + resources :users, :only => [:index, :show] do get :expire, :on => :member end diff --git a/test/test_helpers_test.rb b/test/test_helpers_test.rb index 3c1006d7..32805c6b 100644 --- a/test/test_helpers_test.rb +++ b/test/test_helpers_test.rb @@ -10,14 +10,28 @@ class TestHelpersTest < ActionController::TestCase assert_equal "You need to sign in or sign up before continuing.", flash[:alert] end - test "redirects if attempting to access a page with a unconfirmed account" do + test "redirects if attempting to access a page with an unconfirmed account" do swap Devise, :confirm_within => 0 do - sign_in create_user + user = create_user + assert !user.active? + + sign_in user get :index assert_redirected_to new_user_session_path end end + test "returns nil if accessing current_user with an unconfirmed account" do + swap Devise, :confirm_within => 0 do + user = create_user + assert !user.active? + + sign_in user + get :show, :id => user + assert_nil assigns(:current_user) + end + end + test "does not redirect with valid user" do user = create_user user.confirm!