Add fragment support for `store_location_for`

This commit is contained in:
Jimmy Bourassa 2014-11-05 16:52:40 -05:00
parent d67388ad98
commit 5dedd8c4cf
2 changed files with 8 additions and 1 deletions

View File

@ -35,7 +35,9 @@ module Devise
session_key = stored_location_key_for(resource_or_scope) session_key = stored_location_key_for(resource_or_scope)
uri = parse_uri(location) uri = parse_uri(location)
if uri if uri
session[session_key] = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?') path = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?')
path = [path, uri.fragment].compact.join('#')
session[session_key] = path
end end
end end

View File

@ -245,6 +245,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
assert_equal "/foo?bar=baz", @controller.stored_location_for(:user) assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
end end
test 'store location for stores fragments' do
@controller.store_location_for(:user, "/foo#bar")
assert_equal "/foo#bar", @controller.stored_location_for(:user)
end
test 'after sign in path defaults to root path if none by was specified for the given scope' do test 'after sign in path defaults to root path if none by was specified for the given scope' do
assert_equal root_path, @controller.after_sign_in_path_for(:user) assert_equal root_path, @controller.after_sign_in_path_for(:user)
end end