Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure namespaces has proper scoped views, closes #654

  • Loading branch information...
commit d8016ea3fd51ee552bc193afff4db2364efb8be1 1 parent 6bfcbef
@josevalim josevalim authored
View
1  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
View
2  app/mailers/devise/mailer.rb
@@ -60,7 +60,7 @@ def mailer_sender(mapping)
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
View
2  lib/devise/controllers/scoped_views.rb
@@ -20,7 +20,7 @@ def scoped_views=(value)
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
View
6 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 @@ def self.find_by_path!(path, path_type=:fullpath)
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)
View
2  lib/devise/rails/routes.rb
@@ -178,7 +178,7 @@ def devise_for(*resources)
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
View
12 test/mapping_test.rb
@@ -12,9 +12,19 @@ def fake_request(path, params={})
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
Please sign in to comment.
Something went wrong with that request. Please try again.