Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ensure namespaces has proper scoped views, closes #654

  • Loading branch information...
commit d8016ea3fd51ee552bc193afff4db2364efb8be1 1 parent 6bfcbef
José Valim josevalim authored
1  CHANGELOG.rdoc
Source Rendered
@@ -31,6 +31,7 @@
31 31 * Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov)
32 32 * FailureApp now properly handles nil request.format
33 33 * Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7
  34 + * Ensure namespaces has proper scoped views
34 35
35 36 == 1.1.3
36 37
2  app/mailers/devise/mailer.rb
@@ -60,7 +60,7 @@ def mailer_sender(mapping)
60 60
61 61 def template_paths
62 62 template_path = [self.class.mailer_name]
63   - template_path.unshift "#{@devise_mapping.plural}/mailer" if self.class.scoped_views?
  63 + template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
64 64 template_path
65 65 end
66 66
2  lib/devise/controllers/scoped_views.rb
@@ -20,7 +20,7 @@ def scoped_views=(value)
20 20 def render_with_scope(action, path=self.controller_path)
21 21 if self.class.scoped_views?
22 22 begin
23   - render :template => "#{devise_mapping.plural}/#{path.split("/").last}/#{action}"
  23 + render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}"
24 24 rescue ActionView::MissingTemplate
25 25 render :template => "#{path}/#{action}"
26 26 end
6 lib/devise/mapping.rb
@@ -22,7 +22,7 @@ module Devise
22 22 # # is the modules included in the class
23 23 #
24 24 class Mapping #:nodoc:
25   - attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name, :sign_out_via
  25 + attr_reader :singular, :scoped_path, :path, :controllers, :path_names, :class_name, :sign_out_via
26 26 alias :name :singular
27 27
28 28 # 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)
46 46 end
47 47
48 48 def initialize(name, options) #:nodoc:
49   - @plural = (options[:as] ? "#{options[:as]}_#{name}" : name).to_sym
50   - @singular = (options[:singular] || @plural.to_s.singularize).to_sym
  49 + @scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s
  50 + @singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
51 51
52 52 @class_name = (options[:class_name] || name.to_s.classify).to_s
53 53 @ref = ActiveSupport::Dependencies.ref(@class_name)
2  lib/devise/rails/routes.rb
@@ -178,7 +178,7 @@ def devise_for(*resources)
178 178 devise_scope mapping.name do
179 179 yield if block_given?
180 180 with_devise_exclusive_scope mapping.fullpath, mapping.name do
181   - routes.each { |mod| send(:"devise_#{mod}", mapping, mapping.controllers) }
  181 + routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
182 182 end
183 183 end
184 184 end
12 test/mapping_test.rb
@@ -12,9 +12,19 @@ def fake_request(path, params={})
12 12 mapping = Devise.mappings[:user]
13 13 assert_equal User, mapping.to
14 14 assert_equal User.devise_modules, mapping.modules
15   - assert_equal :users, mapping.plural
  15 + assert_equal "users", mapping.scoped_path
16 16 assert_equal :user, mapping.singular
17 17 assert_equal "users", mapping.path
  18 + assert_equal "/users", mapping.fullpath
  19 + end
  20 +
  21 + test 'store options with namespace' do
  22 + mapping = Devise.mappings[:publisher_account]
  23 + assert_equal Admin, mapping.to
  24 + assert_equal "publisher/accounts", mapping.scoped_path
  25 + assert_equal :publisher_account, mapping.singular
  26 + assert_equal "accounts", mapping.path
  27 + assert_equal "/publisher/accounts", mapping.fullpath
18 28 end
19 29
20 30 test 'allows path to be given' do

0 comments on commit d8016ea

Please sign in to comment.
Something went wrong with that request. Please try again.