From d8016ea3fd51ee552bc193afff4db2364efb8be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 20 Nov 2010 21:41:26 +0100 Subject: [PATCH] Ensure namespaces has proper scoped views, closes #654 --- CHANGELOG.rdoc | 1 + app/mailers/devise/mailer.rb | 2 +- lib/devise/controllers/scoped_views.rb | 2 +- lib/devise/mapping.rb | 6 +++--- lib/devise/rails/routes.rb | 2 +- test/mapping_test.rb | 12 +++++++++++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index c61e8101..f5b0795e 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -31,6 +31,7 @@ * Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov) * FailureApp now properly handles nil request.format * Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7 + * Ensure namespaces has proper scoped views == 1.1.3 diff --git a/app/mailers/devise/mailer.rb b/app/mailers/devise/mailer.rb index ade51ca9..5b888749 100644 --- a/app/mailers/devise/mailer.rb +++ b/app/mailers/devise/mailer.rb @@ -60,7 +60,7 @@ class Devise::Mailer < ::ActionMailer::Base def template_paths template_path = [self.class.mailer_name] - template_path.unshift "#{@devise_mapping.plural}/mailer" if self.class.scoped_views? + template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views? template_path end diff --git a/lib/devise/controllers/scoped_views.rb b/lib/devise/controllers/scoped_views.rb index 0736a0f9..0432aea1 100644 --- a/lib/devise/controllers/scoped_views.rb +++ b/lib/devise/controllers/scoped_views.rb @@ -20,7 +20,7 @@ module Devise def render_with_scope(action, path=self.controller_path) if self.class.scoped_views? begin - render :template => "#{devise_mapping.plural}/#{path.split("/").last}/#{action}" + render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}" rescue ActionView::MissingTemplate render :template => "#{path}/#{action}" end diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 2c81ecaa..8a1d25ff 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -22,7 +22,7 @@ module Devise # # is the modules included in the class # class Mapping #:nodoc: - attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name, :sign_out_via + attr_reader :singular, :scoped_path, :path, :controllers, :path_names, :class_name, :sign_out_via alias :name :singular # Receives an object and find a scope for it. If a scope cannot be found, @@ -46,8 +46,8 @@ module Devise end def initialize(name, options) #:nodoc: - @plural = (options[:as] ? "#{options[:as]}_#{name}" : name).to_sym - @singular = (options[:singular] || @plural.to_s.singularize).to_sym + @scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s + @singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym @class_name = (options[:class_name] || name.to_s.classify).to_s @ref = ActiveSupport::Dependencies.ref(@class_name) diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 75e6f6ed..7ac74926 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -178,7 +178,7 @@ module ActionDispatch::Routing devise_scope mapping.name do yield if block_given? with_devise_exclusive_scope mapping.fullpath, mapping.name do - routes.each { |mod| send(:"devise_#{mod}", mapping, mapping.controllers) } + routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) } end end end diff --git a/test/mapping_test.rb b/test/mapping_test.rb index 950aa9ad..97de0863 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -12,9 +12,19 @@ class MappingTest < ActiveSupport::TestCase mapping = Devise.mappings[:user] assert_equal User, mapping.to assert_equal User.devise_modules, mapping.modules - assert_equal :users, mapping.plural + assert_equal "users", mapping.scoped_path assert_equal :user, mapping.singular assert_equal "users", mapping.path + assert_equal "/users", mapping.fullpath + end + + test 'store options with namespace' do + mapping = Devise.mappings[:publisher_account] + assert_equal Admin, mapping.to + assert_equal "publisher/accounts", mapping.scoped_path + assert_equal :publisher_account, mapping.singular + assert_equal "accounts", mapping.path + assert_equal "/publisher/accounts", mapping.fullpath end test 'allows path to be given' do