don't delete the return to url from session if the requested format is not navigational

closes #2122
This commit is contained in:
Vasiliy Ermolovich 2012-11-04 23:34:20 +03:00
parent ee61d86546
commit 61903b534a
2 changed files with 37 additions and 4 deletions

View File

@ -162,8 +162,8 @@ module Devise
users.any?
end
# Returns and delete the url stored in the session for the given scope. Useful
# for giving redirect backs after sign up:
# Returns and delete (if it's navigational format) the url stored in the session for
# the given scope. Useful for giving redirect backs after sign up:
#
# Example:
#
@ -171,7 +171,12 @@ module Devise
#
def stored_location_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
session.delete("#{scope}_return_to")
if is_navigational_format?
session.delete("#{scope}_return_to")
else
session["#{scope}_return_to"]
end
end
# The scope root url to be used when he's signed in. By default, it first

View File

@ -13,6 +13,34 @@ class SessionsControllerTest < ActionController::TestCase
end
end
test "#create delete the url stored in the session if the requested format is navigational" do
request.env["devise.mapping"] = Devise.mappings[:user]
request.session["user_return_to"] = 'foo.bar'
user = create_user
user.confirm!
post :create, :user => {
:email => user.email,
:password => user.password
}
assert_nil request.session["user_return_to"]
end
test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
request.env["devise.mapping"] = Devise.mappings[:user]
request.session["user_return_to"] = 'foo.bar'
user = create_user
user.confirm!
post :create, :format => 'json', :user => {
:email => user.email,
:password => user.password
}
assert_equal 'foo.bar', request.session["user_return_to"]
end
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create, :user => {
@ -54,4 +82,4 @@ class SessionsControllerTest < ActionController::TestCase
end
end
end
end
end