From bc05d28d3f92e2cebc9f7d84bcf04c9bd66fc896 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 22 Jan 2010 19:50:32 +0800 Subject: [PATCH] Devise::Mapping#raw_path does not consider relative_url_root so that route helpers work (no more session_path(:user) => '/abc/abc/users/sign_in') Devise::Mapping#parsed_path considers relative_url_root so that initial redirects still work with non empty relative_url_roots --- lib/devise/mapping.rb | 4 ++-- test/mapping_test.rb | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index e3ee51f8..5fa9913e 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -94,7 +94,7 @@ module Devise # Returns the raw path using the current relative_url_root, path_prefix and as. def raw_path - ActionController::Base.relative_url_root.to_s + path_prefix + as.to_s + path_prefix + as.to_s end # Returns the parsed path. If you need meta information in your path_prefix, @@ -102,7 +102,7 @@ module Devise # by default is I18n.locale. # def parsed_path - returning raw_path do |path| + returning (ActionController::Base.relative_url_root.to_s + raw_path) do |path| self.class.default_url_options.each do |key, value| path.gsub!(key.inspect, value.to_param) end diff --git a/test/mapping_test.rb b/test/mapping_test.rb index 981af08a..8d882351 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -97,18 +97,12 @@ class MappingTest < ActiveSupport::TestCase assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path end - test 'raw path adds in the relative_url_root' do - swap ActionController::Base, :relative_url_root => '/abc' do - assert_equal '/abc/users', Devise.mappings[:user].raw_path - end - end - - test 'raw path deals with a nil relative_url_root' do - swap ActionController::Base, :relative_url_root => nil do + test 'raw path ignores the relative_url_root' do + swap ActionController::Base, :relative_url_root => "/abc" do assert_equal '/users', Devise.mappings[:user].raw_path end end - + test 'parsed path is returned' do begin Devise.default_url_options {{ :locale => I18n.locale }} @@ -119,12 +113,18 @@ class MappingTest < ActiveSupport::TestCase end end - test 'parsed path deals with non-standard relative_url_roots' do - swap ActionController::Base, :relative_url_root => "/abc" do + test 'parsed path adds in the relative_url_root' do + swap ActionController::Base, :relative_url_root => '/abc' do assert_equal '/abc/users', Devise.mappings[:user].parsed_path end end - + + test 'parsed path deals with a nil relative_url_root' do + swap ActionController::Base, :relative_url_root => nil do + assert_equal '/users', Devise.mappings[:user].raw_path + end + end + test 'should have default route options' do assert_equal({}, Devise.mappings[:user].route_options) end