Ensure namespaces has proper scoped views, closes #654

This commit is contained in:
José Valim 2010-11-20 21:41:26 +01:00
parent 6bfcbeffdd
commit d8016ea3fd
6 changed files with 18 additions and 7 deletions

View File

@ -31,6 +31,7 @@
* Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov) * Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov)
* FailureApp now properly handles nil request.format * FailureApp now properly handles nil request.format
* Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7 * Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7
* Ensure namespaces has proper scoped views
== 1.1.3 == 1.1.3

View File

@ -60,7 +60,7 @@ class Devise::Mailer < ::ActionMailer::Base
def template_paths def template_paths
template_path = [self.class.mailer_name] 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 template_path
end end

View File

@ -20,7 +20,7 @@ module Devise
def render_with_scope(action, path=self.controller_path) def render_with_scope(action, path=self.controller_path)
if self.class.scoped_views? if self.class.scoped_views?
begin begin
render :template => "#{devise_mapping.plural}/#{path.split("/").last}/#{action}" render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}"
rescue ActionView::MissingTemplate rescue ActionView::MissingTemplate
render :template => "#{path}/#{action}" render :template => "#{path}/#{action}"
end end

View File

@ -22,7 +22,7 @@ module Devise
# # is the modules included in the class # # is the modules included in the class
# #
class Mapping #:nodoc: 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 alias :name :singular
# Receives an object and find a scope for it. If a scope cannot be found, # Receives an object and find a scope for it. If a scope cannot be found,
@ -46,8 +46,8 @@ module Devise
end end
def initialize(name, options) #:nodoc: def initialize(name, options) #:nodoc:
@plural = (options[:as] ? "#{options[:as]}_#{name}" : name).to_sym @scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s
@singular = (options[:singular] || @plural.to_s.singularize).to_sym @singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
@class_name = (options[:class_name] || name.to_s.classify).to_s @class_name = (options[:class_name] || name.to_s.classify).to_s
@ref = ActiveSupport::Dependencies.ref(@class_name) @ref = ActiveSupport::Dependencies.ref(@class_name)

View File

@ -178,7 +178,7 @@ module ActionDispatch::Routing
devise_scope mapping.name do devise_scope mapping.name do
yield if block_given? yield if block_given?
with_devise_exclusive_scope mapping.fullpath, mapping.name do 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 end
end end

View File

@ -12,9 +12,19 @@ class MappingTest < ActiveSupport::TestCase
mapping = Devise.mappings[:user] mapping = Devise.mappings[:user]
assert_equal User, mapping.to assert_equal User, mapping.to
assert_equal User.devise_modules, mapping.modules 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 :user, mapping.singular
assert_equal "users", mapping.path 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 end
test 'allows path to be given' do test 'allows path to be given' do