From 7e5d0ac7362c91e1e925badee976cb91a84e78d9 Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Wed, 7 Jan 2015 12:25:16 -0200 Subject: [PATCH] Add tests for translation scope being preserved when inheriting a controller issue #3367 --- ...inherited_controller_i18n_messages_test.rb | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/controllers/inherited_controller_i18n_messages_test.rb diff --git a/test/controllers/inherited_controller_i18n_messages_test.rb b/test/controllers/inherited_controller_i18n_messages_test.rb new file mode 100644 index 0000000000..66d2df49f9 --- /dev/null +++ b/test/controllers/inherited_controller_i18n_messages_test.rb @@ -0,0 +1,51 @@ +require 'test_helper' + +class SessionsInheritedController < Devise::SessionsController + def test_i18n_scope + set_flash_message(:notice, :signed_in) + end +end + +class AnotherInheritedController < SessionsInheritedController + protected + + def translation_scope + 'another' + end +end + +class InheritedControllerTest < ActionController::TestCase + tests SessionsInheritedController + + def setup + @mock_warden = OpenStruct.new + @controller.request.env['warden'] = @mock_warden + @controller.request.env['devise.mapping'] = Devise.mappings[:user] + end + + test 'I18n scope is inherited from Devise::Sessions' do + I18n.expects(:t).with do |message, options| + message == 'user.signed_in' && + options[:scope] == 'devise.sessions' + end + @controller.test_i18n_scope + end +end + +class AnotherInheritedControllerTest < ActionController::TestCase + tests AnotherInheritedController + + def setup + @mock_warden = OpenStruct.new + @controller.request.env['warden'] = @mock_warden + @controller.request.env['devise.mapping'] = Devise.mappings[:user] + end + + test 'I18n scope is overridden' do + I18n.expects(:t).with do |message, options| + message == 'user.signed_in' && + options[:scope] == 'another' + end + @controller.test_i18n_scope + end +end