Skip to content

Commit 12ef929

Browse files
committed
Fix test
1 parent 95d27cd commit 12ef929

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

test/functional/custom_message_settings_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
require File.dirname(__FILE__) + '/../test_helper'
22

33
class CustomMessageSettingsControllerTest < defined?(Redmine::ControllerTest) ? Redmine::ControllerTest : ActionController::TestCase
4-
fixtures :custom_message_settings, :users
4+
fixtures :users, :email_addresses, :roles, :custom_message_settings
55
include Redmine::I18n
66
prepend ::RailsKwargsTesting::ControllerMethods if defined?(RailsKwargsTesting)
77

88
def setup
99
@request.session[:user_id] = 1 # admin
10-
MessageCustomize::Locale.reload!('en')
10+
MessageCustomize::Locale.reload!(['en', 'ja'])
1111
Rails.application.config.i18n.load_path = (Rails.application.config.i18n.load_path + Dir.glob(Rails.root.join('plugins', 'redmine_message_customize', 'config', 'locales', 'custom_messages', '*.rb'))).uniq
1212
end
1313

test/integration/application_controller_patch_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ def setup
1111
end
1212

1313
def test_reload_if_messages_are_not_latest
14-
User.find_by_login('admin').update(language: 'ja')
1514
log_user('admin', 'admin')
1615
custom_message_setting = CustomMessageSetting.find_or_default
1716

1817
# 値が書き換わっただけでは用語は置き換わらない(MessageCustomize::Locale.reload!の実行が必要)
19-
custom_message_setting.update_with_custom_messages({'label_home' => 'Changed home'}, 'ja')
20-
assert_equal 'Home2', I18n.backend.send(:translations)[:ja][:label_home]
21-
assert_equal '1640995200', I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
18+
custom_message_setting.update_with_custom_messages({'label_home' => 'Changed home'}, 'en')
19+
assert_equal 'Home1', I18n.backend.send(:translations)[:en][:label_home]
20+
assert_equal '1640995200', I18n.backend.send(:translations)[:en][:redmine_message_customize_timestamp]
2221

2322
# ApplicationControllerのbefore_actionによって、redmine_message_customize_timestampの値を見て最新かが判断される
2423
# get '/issues'は最新じゃない状態でのリクエストのためMessageCustomize::Locale.reload!が実行されること
2524
get '/issues'
26-
assert_equal 'Changed home', I18n.backend.send(:translations)[:ja][:label_home]
27-
assert_equal custom_message_setting.updated_on.to_i.to_s, I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
25+
assert_equal 'Changed home', I18n.backend.send(:translations)[:en][:label_home]
26+
assert_equal custom_message_setting.updated_on.to_i.to_s, I18n.backend.send(:translations)[:en][:redmine_message_customize_timestamp]
2827
end
2928

3029
def test_reload_if_user_language_is_auto_and_default_language_messages_are_not_latest
3130
# User.currentのlanguageが''(auto)でもSetting.default_languageを元に用語の最新化を行うこと
3231
User.find_by_login('admin').update(language: '')
33-
Setting.default_language = 'ja'
3432
log_user('admin', 'admin')
3533
custom_message_setting = CustomMessageSetting.find_or_default
3634

3735
custom_message_setting.update_with_custom_messages({'label_home' => 'Changed home'}, 'ja')
3836
assert_equal 'Home2', I18n.backend.send(:translations)[:ja][:label_home]
3937
assert_equal '1640995200', I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
4038

41-
get '/issues'
39+
with_settings :default_language => 'ja' do
40+
get '/issues'
41+
end
4242
assert_equal 'Changed home', I18n.backend.send(:translations)[:ja][:label_home]
4343
assert_equal custom_message_setting.updated_on.to_i.to_s, I18n.backend.send(:translations)[:ja][:redmine_message_customize_timestamp]
4444
end

test/unit/custom_message_setting_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
require File.dirname(__FILE__) + '/../test_helper'
22

33
class CustomMessageSettingTest < ActiveSupport::TestCase
4-
fixtures :custom_message_settings
4+
fixtures :users, :email_addresses, :roles, :custom_message_settings
55
include Redmine::I18n
66

77
def setup
8+
User.current = User.find_by(login: 'admin')
89
@custom_message_setting = CustomMessageSetting.find(1)
9-
MessageCustomize::Locale.reload!('en')
10+
MessageCustomize::Locale.reload!(['en', 'ja'])
1011
Rails.application.config.i18n.load_path = (Rails.application.config.i18n.load_path + Dir.glob(Rails.root.join('plugins', 'redmine_message_customize', 'config', 'locales', 'custom_messages', '*.rb'))).uniq
1112
end
1213

test/unit/lib/message_customize/locale_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class LocaleTest < ActiveSupport::TestCase
55
include Redmine::I18n
66

77
def setup
8-
MessageCustomize::Locale.reload!('en')
8+
MessageCustomize::Locale.reload!(['en', 'ja'])
99
Rails.application.config.i18n.load_path = (Rails.application.config.i18n.load_path + Dir.glob(Rails.root.join('plugins', 'redmine_message_customize', 'config', 'locales', 'custom_messages', '*.rb'))).uniq
1010
end
1111

@@ -18,7 +18,7 @@ def test_reload!
1818
setting.save
1919

2020
assert_equal 'Home1', I18n.backend.send(:translations)[:en][:label_home]
21-
MessageCustomize::Locale.reload!('en')
21+
MessageCustomize::Locale.reload!(['en'])
2222
assert_equal 'Changed home', I18n.backend.send(:translations)[:en][:label_home]
2323
assert_equal [:en], MessageCustomize::Locale.instance_variable_get(:@available_messages).keys
2424
end

0 commit comments

Comments
 (0)