From 379d8c69a5c02dede6230719f3ebcc8bb95a655b Mon Sep 17 00:00:00 2001 From: siong1987 Date: Thu, 23 Dec 2010 02:17:11 +0800 Subject: [PATCH] Issue 675: recall option is now passed for not confirmed email and inactive account. --- lib/devise/failure_app.rb | 2 +- lib/devise/hooks/activatable.rb | 6 +++--- test/failure_app_test.rb | 24 +++++++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index 9127764f..921cfa08 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -40,7 +40,7 @@ module Devise def recall env["PATH_INFO"] = attempted_path - flash.now[:alert] = i18n_message(:invalid) + flash.now[:alert] = i18n_message(warden_options[:message] || :invalid) self.response = recall_app(warden_options[:recall]).call(env) end diff --git a/lib/devise/hooks/activatable.rb b/lib/devise/hooks/activatable.rb index d2d86d41..55eac05a 100644 --- a/lib/devise/hooks/activatable.rb +++ b/lib/devise/hooks/activatable.rb @@ -4,8 +4,8 @@ # in each request and in case the user is using other strategies beside Devise ones. Warden::Manager.after_set_user do |record, warden, options| if record && record.respond_to?(:active?) && !record.active? - scope = options[:scope] - warden.logout(scope) - throw :warden, :scope => scope, :message => record.inactive_message + warden.logout(options[:scope]) + options.merge!(:message => record.inactive_message) + throw :warden, options end end \ No newline at end of file diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 6cf82b4d..83d12efa 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -144,7 +144,7 @@ class FailureTest < ActiveSupport::TestCase end context 'With recall' do - test 'calls the original controller' do + test 'calls the original controller if invalid email or password' do env = { "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" }, "devise.mapping" => Devise.mappings[:user], @@ -154,5 +154,27 @@ class FailureTest < ActiveSupport::TestCase assert @response.third.body.include?('

Sign in

') assert @response.third.body.include?('Invalid email or password.') end + + test 'calls the original controller if not confirmed email' do + env = { + "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed }, + "devise.mapping" => Devise.mappings[:user], + "warden" => stub_everything + } + call_failure(env) + assert @response.third.body.include?('

Sign in

') + assert @response.third.body.include?('You have to confirm your account before continuing.') + end + + test 'calls the original controller if inactive account' do + env = { + "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive }, + "devise.mapping" => Devise.mappings[:user], + "warden" => stub_everything + } + call_failure(env) + assert @response.third.body.include?('

Sign in

') + assert @response.third.body.include?('Your account was not activated yet.') + end end end