Skip to content

Commit

Permalink
Issue 675: recall option is now passed for not confirmed email and in…
Browse files Browse the repository at this point in the history
…active account.
  • Loading branch information
siong1987 authored and josevalim committed Dec 22, 2010
1 parent 13e8bc2 commit 379d8c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/devise/failure_app.rb
Expand Up @@ -40,7 +40,7 @@ def http_auth

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

Expand Down
6 changes: 3 additions & 3 deletions lib/devise/hooks/activatable.rb
Expand Up @@ -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
24 changes: 23 additions & 1 deletion test/failure_app_test.rb
Expand Up @@ -144,7 +144,7 @@ def call_failure(env_params={})
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],
Expand All @@ -154,5 +154,27 @@ def call_failure(env_params={})
assert @response.third.body.include?('<h2>Sign in</h2>')
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?('<h2>Sign in</h2>')
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?('<h2>Sign in</h2>')
assert @response.third.body.include?('Your account was not activated yet.')
end
end
end

0 comments on commit 379d8c6

Please sign in to comment.