From 5eebf74f6921e88e8685ca74a37e59d9259ba530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 12 Dec 2011 09:25:19 +0100 Subject: [PATCH] Fix a bug where passing :format => false to devise_for was permanent, closes #1504 --- lib/devise/mapping.rb | 5 +---- lib/devise/rails/routes.rb | 15 +++++++++------ test/routes_test.rb | 4 ++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 3fa69f25..84d63864 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -23,8 +23,7 @@ module Devise # class Mapping #:nodoc: attr_reader :singular, :scoped_path, :path, :controllers, :path_names, - :class_name, :sign_out_via, :format, :used_routes, :used_helpers, - :constraints, :defaults, :failure_app + :class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app alias :name :singular @@ -64,8 +63,6 @@ module Devise default_failure_app(options) default_controllers(options) default_path_names(options) - default_constraints(options) - default_defaults(options) default_used_route(options) default_used_helpers(options) end diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 2ce81ab0..3127c264 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -185,7 +185,7 @@ module ActionDispatch::Routing options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {}) options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {}) options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {}) - @scope[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false + options[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false resources.map!(&:to_sym) @@ -208,7 +208,7 @@ module ActionDispatch::Routing devise_scope mapping.name do yield if block_given? - with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do + with_devise_exclusive_scope mapping.fullpath, mapping.name, options do routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) } end end @@ -368,12 +368,15 @@ module ActionDispatch::Routing @scope[:path] = path end - def with_devise_exclusive_scope(new_path, new_as, new_constraints, new_defaults) #:nodoc: - old_as, old_path, old_module, old_constraints, old_defaults = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] - @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = new_as, new_path, nil, new_constraints, new_defaults + def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc: + old_as, old_path, old_module, old_constraints, old_defaults, old_options = + *@scope.values_at(:as, :path, :module, :constraints, :defaults, :options) + @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] = + new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options) yield ensure - @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults + @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] = + old_as, old_path, old_module, old_constraints, old_defaults, old_options end def raise_no_devise_method_error!(klass) #:nodoc: diff --git a/test/routes_test.rb b/test/routes_test.rb index f243d84d..d3f0ceff 100644 --- a/test/routes_test.rb +++ b/test/routes_test.rb @@ -225,6 +225,10 @@ class CustomizedRoutingTest < ActionController::TestCase assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => '/htmlonly_users/unlock.xml', :method => :get}) end end + + test 'map with format false is not permanent' do + assert_equal "/set.xml", @routes.url_helpers.set_path(:xml) + end end class ScopedRoutingTest < ActionController::TestCase