mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Ensure namespaces has proper scoped views, closes #654
This commit is contained in:
parent
6bfcbeffdd
commit
d8016ea3fd
6 changed files with 18 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue