From 5dedd8c4cfc06c8eebc72fc1823683c5c511be63 Mon Sep 17 00:00:00 2001 From: Jimmy Bourassa Date: Wed, 5 Nov 2014 16:52:40 -0500 Subject: [PATCH] Add fragment support for `store_location_for` --- lib/devise/controllers/store_location.rb | 4 +++- test/controllers/helpers_test.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/devise/controllers/store_location.rb b/lib/devise/controllers/store_location.rb index ad36a4f0..84adbaaa 100644 --- a/lib/devise/controllers/store_location.rb +++ b/lib/devise/controllers/store_location.rb @@ -35,7 +35,9 @@ module Devise session_key = stored_location_key_for(resource_or_scope) uri = parse_uri(location) 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 diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 4563b66c..bae10c25 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -245,6 +245,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase assert_equal "/foo?bar=baz", @controller.stored_location_for(:user) 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 assert_equal root_path, @controller.after_sign_in_path_for(:user) end