Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Accept devise_i18n_options to handle custom i18n values, closes #1633

  • Loading branch information...
commit fb8e09338907264bb5d4f9917f1d29f8f5e96f2f 1 parent 4b47c3a
José Valim josevalim authored
3  app/controllers/devise_controller.rb
View
@@ -131,6 +131,7 @@ def set_flash_message(key, kind, options={})
options[:scope] = "devise.#{controller_name}"
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name
+ options = devise_i18n_options(options) if respond_to?(:devise_i18n_options, true)
message = I18n.t("#{resource_name}.#{kind}", options)
flash[key] = message if message.present?
end
@@ -155,7 +156,7 @@ def is_navigational_format?
# Override prefixes to consider the scoped view.
def _prefixes #:nodoc:
- @_prefixes ||= if self.class.scoped_views?
+ @_prefixes ||= if self.class.scoped_views? && devise_mapping
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
else
super
16 test/controllers/internal_helpers_test.rb
View
@@ -71,19 +71,21 @@ def setup
end
test 'does not issue blank flash messages' do
- MyController.send(:public, :set_flash_message)
I18n.stubs(:t).returns(' ')
- @controller.set_flash_message :notice, :send_instructions
+ @controller.send :set_flash_message, :notice, :send_instructions
assert flash[:notice].nil?
- MyController.send(:protected, :set_flash_message)
end
test 'issues non-blank flash messages normally' do
- MyController.send(:public, :set_flash_message)
I18n.stubs(:t).returns('non-blank')
- @controller.set_flash_message :notice, :send_instructions
- assert flash[:notice] == 'non-blank'
- MyController.send(:protected, :set_flash_message)
+ @controller.send :set_flash_message, :notice, :send_instructions
+ assert_equal 'non-blank', flash[:notice]
+ end
+
+ test 'uses custom i18n options' do
+ @controller.stubs(:devise_i18n_options).returns(:default => "devise custom options")
+ @controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
+ assert_equal 'devise custom options', flash[:notice]
end
test 'navigational_formats not returning a wild card' do
Please sign in to comment.
Something went wrong with that request. Please try again.