i18n-active_record 0.4.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,136 +1,175 @@
1
- require_relative './test_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
 
3
5
  class I18nBackendActiveRecordTest < I18n::TestCase
4
6
  def setup
7
+ super
8
+
9
+ I18n::Backend::ActiveRecord::Translation.destroy_all
5
10
  I18n.backend = I18n::Backend::ActiveRecord.new
6
- store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
11
+
12
+ store_translations(:en, foo: { bar: 'bar', baz: 'baz' })
7
13
  end
8
14
 
9
15
  def teardown
10
- I18n::Backend::ActiveRecord::Translation.destroy_all
11
16
  I18n::Backend::ActiveRecord.instance_variable_set :@config, I18n::Backend::ActiveRecord::Configuration.new
17
+
12
18
  super
13
19
  end
14
20
 
15
- test "store_translations does not allow ambiguous keys (1)" do
16
- I18n::Backend::ActiveRecord::Translation.delete_all
17
- I18n.backend.store_translations(:en, :foo => 'foo')
18
- I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
19
- I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
21
+ class WithoutCacheTest < I18nBackendActiveRecordTest
22
+ def setup
23
+ super
20
24
 
21
- translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
22
- assert_equal %w(bar baz), translations.map(&:value)
25
+ I18n::Backend::ActiveRecord.config.cache_translations = false
26
+ end
23
27
 
24
- assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t(:foo))
25
- end
28
+ test 'store_translations does not allow ambiguous keys (1)' do
29
+ store_translations(:en, foo: 'foo')
30
+ store_translations(:en, foo: { bar: 'bar' })
31
+ store_translations(:en, foo: { baz: 'baz' })
26
32
 
27
- test "store_translations does not allow ambiguous keys (2)" do
28
- I18n::Backend::ActiveRecord::Translation.delete_all
29
- I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
30
- I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
31
- I18n.backend.store_translations(:en, :foo => 'foo')
33
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
34
+ assert_equal %w[bar baz], translations.map(&:value)
32
35
 
33
- translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
34
- assert_equal %w(foo), translations.map(&:value)
36
+ assert_equal({ bar: 'bar', baz: 'baz' }, I18n.t(:foo))
37
+ end
35
38
 
36
- assert_equal 'foo', I18n.t(:foo)
37
- end
39
+ test 'store_translations does not allow ambiguous keys (2)' do
40
+ store_translations(:en, foo: { bar: 'bar' })
41
+ store_translations(:en, foo: { baz: 'baz' })
42
+ store_translations(:en, foo: 'foo')
38
43
 
39
- test "can store translations with keys that are translations containing special chars" do
40
- I18n.backend.store_translations(:es, :"Pagina's" => "Pagina's" )
41
- assert_equal "Pagina's", I18n.t(:"Pagina's", :locale => :es)
42
- end
44
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
45
+ assert_equal %w[foo], translations.map(&:value)
43
46
 
44
- test "missing translations table does not cause an error in #available_locales" do
45
- I18n::Backend::ActiveRecord::Translation.expects(:available_locales).raises(::ActiveRecord::StatementInvalid, 'msg')
46
- assert_equal [], I18n.backend.available_locales
47
- end
47
+ assert_equal 'foo', I18n.t(:foo)
48
+ end
48
49
 
49
- test "expand_keys" do
50
- assert_equal %w(foo foo.bar foo.bar.baz), I18n.backend.send(:expand_keys, :'foo.bar.baz')
51
- end
50
+ test 'can store translations with keys that are translations containing special chars' do
51
+ store_translations(:es, "Pagina's": "Pagina's")
52
52
 
53
- test "available_locales returns uniq locales" do
54
- I18n::Backend::ActiveRecord::Translation.delete_all
55
- I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
56
- I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
57
- I18n.backend.store_translations(:de, :foo1 => 'foo')
58
- I18n.backend.store_translations(:de, :foo2 => 'foo')
59
- I18n.backend.store_translations(:uk, :foo3 => 'foo')
60
-
61
- available_locales = I18n::Backend::ActiveRecord::Translation.available_locales
62
- assert_equal 3, available_locales.size
63
- assert_includes available_locales, :en
64
- assert_includes available_locales, :de
65
- assert_includes available_locales, :uk
66
- end
53
+ assert_equal "Pagina's", I18n.t(:"Pagina's", locale: :es)
54
+ end
67
55
 
68
- test "the default configuration has cleanup_with_destroy == false" do
69
- refute I18n::Backend::ActiveRecord.config.cleanup_with_destroy
70
- end
56
+ test 'missing translations table does not cause an error in #available_locales' do
57
+ I18n::Backend::ActiveRecord::Translation
58
+ .expects(:available_locales)
59
+ .raises(::ActiveRecord::StatementInvalid, 'msg')
60
+ assert_equal [], I18n.backend.available_locales
61
+ end
71
62
 
72
- test "the configuration supports cleanup_with_destroy being set" do
73
- I18n::Backend::ActiveRecord.configure do |config|
74
- config.cleanup_with_destroy = true
63
+ test 'expand_keys' do
64
+ assert_equal %w[foo foo.bar foo.bar.baz], I18n.backend.send(:expand_keys, :'foo.bar.baz')
75
65
  end
76
66
 
77
- assert I18n::Backend::ActiveRecord.config.cleanup_with_destroy
78
- end
67
+ test 'available_locales returns uniq locales' do
68
+ store_translations(:en, foo: { bar: 'bar' })
69
+ store_translations(:en, foo: { baz: 'baz' })
70
+ store_translations(:de, foo1: 'foo')
71
+ store_translations(:de, foo2: 'foo')
72
+ store_translations(:uk, foo3: 'foo')
73
+
74
+ available_locales = I18n::Backend::ActiveRecord::Translation.available_locales
75
+ assert_equal 3, available_locales.size
76
+ assert_includes available_locales, :en
77
+ assert_includes available_locales, :de
78
+ assert_includes available_locales, :uk
79
+ end
79
80
 
80
- test "fetching subtree of translations" do
81
- I18n::Backend::ActiveRecord::Translation.delete_all
82
- I18n.backend.store_translations(:en, foo: { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } })
83
- assert_equal I18n.t(:foo), { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } }
84
- end
81
+ test 'the default configuration has cleanup_with_destroy == false' do
82
+ refute I18n::Backend::ActiveRecord.config.cleanup_with_destroy
83
+ end
85
84
 
86
- test "build_translation_hash_by_key" do
87
- translation = I18n::Backend::ActiveRecord::Translation.new(value: 'translation', key: 'foo.bar.fizz.buzz')
88
- expected_hash = { 'bar' => { 'fizz' => { 'buzz' => 'translation' } } }
89
- assert_equal I18n.backend.send(:build_translation_hash_by_key, 'foo', translation), expected_hash
90
- end
85
+ test 'the configuration supports cleanup_with_destroy being set' do
86
+ I18n::Backend::ActiveRecord.configure do |config|
87
+ config.cleanup_with_destroy = true
88
+ end
91
89
 
92
- test "returning all keys via ." do
93
- expected_hash = {:foo => { :bar => 'bar', :baz => 'baz' }}
94
- assert_equal expected_hash, I18n.t('.')
95
- end
90
+ assert I18n::Backend::ActiveRecord.config.cleanup_with_destroy
91
+ end
96
92
 
97
- test "accessing keys with a trailing/leading period" do
98
- expected_hash = { :bar => 'bar', :baz => 'baz' }
99
- assert_equal expected_hash, I18n.t('foo')
100
- assert_equal expected_hash, I18n.t('.foo')
101
- assert_equal expected_hash, I18n.t('foo.')
102
- assert_equal expected_hash, I18n.t('.foo.')
103
- assert_equal expected_hash, I18n.t('.foo.')
104
- end
93
+ test 'fetching subtree of translations' do
94
+ store_translations(:en, foo: { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } })
105
95
 
106
- test "returning all keys via . when there are no keys" do
107
- I18n.t('.') # Fixes test flakiness by loading available locales
108
- I18n::Backend::ActiveRecord::Translation.destroy_all
96
+ assert_equal I18n.t(:foo), { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } }
97
+ end
109
98
 
110
- assert_equal "translation missing: en.no key", I18n.t('.')
111
- end
99
+ test 'build_translation_hash_by_key' do
100
+ translation = I18n::Backend::ActiveRecord::Translation.new(value: 'translation', key: 'foo.bar.fizz.buzz')
101
+ expected_hash = { 'bar' => { 'fizz' => { 'buzz' => 'translation' } } }
112
102
 
113
- test "intially unitinitialized" do
114
- refute I18n.backend.initialized?
115
- I18n.backend.init_translations
116
- assert I18n.backend.initialized?
117
- I18n.backend.reload!
118
- refute I18n.backend.initialized?
119
- I18n.backend.init_translations
120
- assert I18n.backend.initialized?
121
- end
103
+ assert_equal I18n.backend.send(:build_translation_hash_by_key, 'foo', translation), expected_hash
104
+ end
105
+
106
+ test 'returning all keys via .' do
107
+ expected_hash = { foo: { bar: 'bar', baz: 'baz' } }
108
+
109
+ assert_equal expected_hash, I18n.t('.')
110
+ end
111
+
112
+ test 'accessing keys with a trailing/leading period' do
113
+ expected_hash = { bar: 'bar', baz: 'baz' }
114
+
115
+ assert_equal expected_hash, I18n.t('foo')
116
+ assert_equal expected_hash, I18n.t('.foo')
117
+ assert_equal expected_hash, I18n.t('foo.')
118
+ assert_equal expected_hash, I18n.t('.foo.')
119
+ assert_equal expected_hash, I18n.t('.foo.')
120
+ end
121
+
122
+ test 'returning all keys via . when there are no keys' do
123
+ I18n.t('.') # Fixes test flakiness by loading available locales
124
+ I18n::Backend::ActiveRecord::Translation.destroy_all
125
+
126
+ assert_equal 'translation missing: en.no key', I18n.t('.')
127
+ end
128
+
129
+ test 'intially unitinitialized' do
130
+ refute I18n.backend.initialized?
131
+
132
+ I18n.backend.init_translations
133
+ assert I18n.backend.initialized?
122
134
 
123
- test "translations returns all translations" do
124
- expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } }
125
- I18n.backend.init_translations
126
- assert_equal expected_hash, I18n.backend.send(:translations)
127
- assert I18n.backend.initialized?
135
+ I18n.backend.reload!
136
+ refute I18n.backend.initialized?
137
+
138
+ I18n.backend.init_translations
139
+ assert I18n.backend.initialized?
140
+ end
141
+
142
+ test 'translations returns all translations' do
143
+ expected_hash = { en: { foo: { bar: 'bar', baz: 'baz' } } }
144
+ I18n.backend.init_translations
145
+
146
+ assert_equal expected_hash, I18n.backend.send(:translations)
147
+ assert I18n.backend.initialized?
148
+ end
149
+
150
+ test 'translations initialized with do_init argument' do
151
+ expected_hash = { en: { foo: { bar: 'bar', baz: 'baz' } } }
152
+
153
+ refute I18n.backend.initialized?
154
+ assert_equal expected_hash, I18n.backend.send(:translations, do_init: true)
155
+ assert I18n.backend.initialized?
156
+ end
128
157
  end
129
158
 
130
- test "translations initialized with do_init argument" do
131
- expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } }
132
- refute I18n.backend.initialized?
133
- assert_equal expected_hash, I18n.backend.send(:translations, { do_init: true })
134
- assert I18n.backend.initialized?
159
+ class WithCacheTest < WithoutCacheTest
160
+ def setup
161
+ super
162
+
163
+ I18n::Backend::ActiveRecord.config.cache_translations = true
164
+ end
165
+
166
+ test 'reinitialization when the DB is empty' do
167
+ I18n::Backend::ActiveRecord::Translation.destroy_all
168
+
169
+ I18n.backend.init_translations
170
+ I18n.backend.expects(:init_translations).never
171
+
172
+ I18n.t('foo')
173
+ end
135
174
  end
136
175
  end
data/test/api_test.rb CHANGED
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class I18nActiveRecordApiTest < I18n::TestCase
4
6
  def setup
5
7
  I18n.backend = I18n::Backend::ActiveRecord.new
8
+
6
9
  super
7
10
  end
8
11
 
@@ -23,7 +26,7 @@ class I18nActiveRecordApiTest < I18n::TestCase
23
26
  include I18n::Tests::Localization::Time
24
27
  include I18n::Tests::Localization::Procs if can_store_procs?
25
28
 
26
- test "make sure we use an ActiveRecord backend" do
29
+ test 'make sure we use an ActiveRecord backend' do
27
30
  assert_equal I18n::Backend::ActiveRecord, I18n.backend.class
28
31
  end
29
32
  end
data/test/missing_test.rb CHANGED
@@ -1,70 +1,107 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class I18nActiveRecordMissingTest < I18n::TestCase
4
- class Backend < I18n::Backend::ActiveRecord
6
+ class BackendWithMissing < I18n::Backend::ActiveRecord
5
7
  include I18n::Backend::ActiveRecord::Missing
6
8
  end
7
9
 
8
10
  def setup
9
- I18n.backend.store_translations(:en, :bar => 'Bar', :i18n => { :plural => { :keys => [:zero, :one, :other] } })
10
- I18n.backend = I18n::Backend::Chain.new(Backend.new, I18n.backend)
11
- I18n::Backend::ActiveRecord::Translation.delete_all
12
- end
11
+ super
12
+
13
+ I18n::Backend::ActiveRecord::Translation.destroy_all
14
+ I18n.backend = BackendWithMissing.new
13
15
 
14
- test "can persist interpolations" do
15
- translation = I18n::Backend::ActiveRecord::Translation.new(:key => 'foo', :value => 'bar', :locale => :en)
16
- translation.interpolations = %w(count name)
17
- translation.save
18
- assert translation.valid?
16
+ store_translations(:en, bar: 'Bar', i18n: { plural: { keys: %i[zero one other] } })
19
17
  end
20
18
 
21
- test "lookup persists the key" do
22
- I18n.t('foo.bar.baz')
19
+ def teardown
20
+ I18n::Backend::ActiveRecord.instance_variable_set :@config, I18n::Backend::ActiveRecord::Configuration.new
23
21
 
24
- assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
25
- assert I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo.bar.baz')
22
+ super
26
23
  end
27
24
 
28
- test "lookup does not persist the key twice" do
29
- 2.times { I18n.t('foo.bar.baz') }
30
- assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
31
- assert I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo.bar.baz')
32
- end
25
+ class WithoutCacheTest < I18nActiveRecordMissingTest
26
+ def setup
27
+ super
33
28
 
34
- test "lookup persists interpolation keys when looked up directly" do
35
- I18n.t('foo.bar.baz', :cow => "lucy" ) # creates stub translation.
36
- translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
37
- assert translation_stub.interpolates?(:cow)
38
- end
29
+ I18n::Backend::ActiveRecord.config.cache_translations = false
30
+ end
39
31
 
40
- test "creates one stub per pluralization" do
41
- I18n.t('foo', :count => 999)
42
- translations = I18n::Backend::ActiveRecord::Translation.locale(:en).where key: %w{ foo.zero foo.one foo.other }
43
- assert_equal 3, translations.length
44
- end
32
+ test 'can persist interpolations' do
33
+ translation = I18n::Backend::ActiveRecord::Translation.new(key: 'foo', value: 'bar', locale: :en)
34
+ translation.interpolations = %w[count name]
35
+ translation.save
45
36
 
46
- test "creates no stub for base key in pluralization" do
47
- I18n.t('foo', :count => 999)
48
- assert_equal 3, I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo").count
49
- assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo")
50
- end
37
+ assert translation.valid?
38
+ end
51
39
 
52
- test "creates a stub when a custom separator is used" do
53
- I18n.t('foo|baz', :separator => '|')
54
- I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first.update_attributes(:value => 'baz!')
55
- assert_equal 'baz!', I18n.t('foo|baz', :separator => '|')
56
- end
40
+ test 'lookup persists the key' do
41
+ I18n.t('foo.bar.baz')
42
+
43
+ assert_equal 3, I18n::Backend::ActiveRecord::Translation.count
44
+ assert I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo.bar.baz')
45
+ end
46
+
47
+ test 'lookup does not persist the key twice' do
48
+ 2.times { I18n.t('foo.bar.baz') }
49
+
50
+ assert_equal 3, I18n::Backend::ActiveRecord::Translation.count
51
+ assert I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo.bar.baz')
52
+ end
53
+
54
+ test 'lookup persists interpolation keys when looked up directly' do
55
+ I18n.t('foo.bar.baz', cow: 'lucy') # creates stub translation.
56
+ translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
57
57
 
58
- test "creates a stub per pluralization when a custom separator is used" do
59
- I18n.t('foo|bar', :count => 999, :separator => '|')
60
- translations = I18n::Backend::ActiveRecord::Translation.locale(:en).where key: %w{ foo.bar.zero foo.bar.one foo.bar.other }
61
- assert_equal 3, translations.length
58
+ assert translation_stub.interpolates?(:cow)
59
+ end
60
+
61
+ test 'creates one stub per pluralization' do
62
+ I18n.t('foo', count: 999)
63
+ translations = I18n::Backend::ActiveRecord::Translation.locale(:en).where(key: %w[foo.zero foo.one foo.other])
64
+
65
+ assert_equal 3, translations.length
66
+ end
67
+
68
+ test 'creates no stub for base key in pluralization' do
69
+ I18n.t('foo', count: 999)
70
+
71
+ assert_equal 3, I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').count
72
+ assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo')
73
+ end
74
+
75
+ test 'creates a stub when a custom separator is used' do
76
+ I18n.t('foo|baz', separator: '|')
77
+ I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.baz').first.update(value: 'baz!')
78
+
79
+ assert_equal 'baz!', I18n.t('foo|baz', separator: '|')
80
+ end
81
+
82
+ test 'creates a stub per pluralization when a custom separator is used' do
83
+ I18n.t('foo|bar', count: 999, separator: '|')
84
+ translations = I18n::Backend::ActiveRecord::Translation
85
+ .locale(:en)
86
+ .where(key: %w[foo.bar.zero foo.bar.one foo.bar.other])
87
+
88
+ assert_equal 3, translations.length
89
+ end
90
+
91
+ test 'creates a stub when a custom separator is used and the key contains the flatten separator(a dot character)' do
92
+ key = 'foo|baz.zab'
93
+ I18n.t(key, separator: '|')
94
+ I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update(value: 'baz!')
95
+
96
+ assert_equal 'baz!', I18n.t(key, separator: '|')
97
+ end
62
98
  end
63
99
 
64
- test "creates a stub when a custom separator is used and the key contains the flatten separator (a dot character)" do
65
- key = 'foo|baz.zab'
66
- I18n.t(key, :separator => '|')
67
- I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update_attributes(:value => 'baz!')
68
- assert_equal 'baz!', I18n.t(key, :separator => '|')
100
+ class WithCacheTest < WithoutCacheTest
101
+ def setup
102
+ super
103
+
104
+ I18n::Backend::ActiveRecord.config.cache_translations = true
105
+ end
69
106
  end
70
107
  end
data/test/test_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
- $KCODE = 'u' if RUBY_VERSION <= '1.9'
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'minitest/autorun'
5
- require 'mocha/setup'
5
+ require 'mocha/minitest'
6
6
  require 'test_declarative'
7
7
 
8
8
  require 'i18n/active_record'
@@ -15,67 +15,79 @@ rescue LoadError => e
15
15
  puts "can't use ActiveRecord backend because: #{e.message}"
16
16
  rescue ::ActiveRecord::ConnectionNotEstablished
17
17
  require 'i18n/backend/active_record'
18
+
18
19
  case ENV['DB']
19
20
  when 'postgres'
20
- ::ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'i18n_unittest', username: ENV['PG_USER'] || 'i18n', password: '', host: 'localhost'
21
+ ::ActiveRecord::Base.establish_connection(
22
+ adapter: 'postgresql',
23
+ database: 'i18n_unittest',
24
+ username: ENV['PG_USER'] || 'postgres',
25
+ password: ENV['PG_PASSWORD'] || 'postgres',
26
+ host: 'localhost'
27
+ )
21
28
  when 'mysql'
22
- ::ActiveRecord::Base.establish_connection adapter: 'mysql2', database: 'i18n_unittest', username: 'root', password: '', host: 'localhost'
29
+ ::ActiveRecord::Base.establish_connection(
30
+ adapter: 'mysql2',
31
+ database: 'i18n_unittest',
32
+ username: ENV['MYSQL_USER'] || 'root',
33
+ password: ENV['MYSQL_PASSWORD'] || '',
34
+ host: '127.0.0.1'
35
+ )
23
36
  else
24
37
  ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
25
38
  end
39
+
26
40
  ::ActiveRecord::Migration.verbose = false
27
- ::ActiveRecord::Schema.define(:version => 1) do
28
- create_table :translations, :force => true do |t|
41
+ ::ActiveRecord::Schema.define(version: 1) do
42
+ create_table :translations, force: true do |t|
29
43
  t.string :locale
30
44
  t.string :key
31
45
  t.text :value
32
46
  t.text :interpolations
33
- t.boolean :is_proc, :default => false
47
+ t.boolean :is_proc, default: false
34
48
  end
35
- add_index :translations, [:locale, :key], :unique => true
49
+ add_index :translations, %i[locale key], unique: true
36
50
  end
37
51
  end
38
52
 
39
53
  TEST_CASE = defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase
40
54
 
41
- class TEST_CASE
42
- alias :assert_raise :assert_raises
43
- alias :assert_not_equal :refute_equal
55
+ class TEST_CASE # rubocop:disable Naming/ClassAndModuleCamelCase
56
+ alias assert_raise assert_raises
57
+ alias assert_not_equal refute_equal
44
58
 
45
- def assert_nothing_raised(*args)
59
+ def assert_nothing_raised(*_args)
46
60
  yield
47
61
  end
48
62
  end
49
63
 
50
- class I18n::TestCase < TEST_CASE
51
- def setup
52
- I18n.enforce_available_locales = false
53
- I18n.available_locales = []
54
- I18n.locale = :en
55
- I18n.default_locale = :en
56
- I18n.load_path = []
57
- super
58
- end
59
-
60
- def teardown
61
- I18n.enforce_available_locales = false
62
- I18n.available_locales = []
63
- I18n.locale = :en
64
- I18n.default_locale = :en
65
- I18n.load_path = []
66
- I18n.backend = nil
67
- super
68
- end
64
+ module I18n
65
+ class TestCase < TEST_CASE
66
+ def setup
67
+ I18n.enforce_available_locales = false
68
+ I18n.available_locales = []
69
+ I18n.locale = :en
70
+ I18n.default_locale = :en
71
+ I18n.load_path = []
72
+ super
73
+ end
69
74
 
70
- def translations
71
- I18n.backend.instance_variable_get(:@translations)
72
- end
75
+ def teardown
76
+ I18n.enforce_available_locales = false
77
+ I18n.available_locales = []
78
+ I18n.locale = :en
79
+ I18n.default_locale = :en
80
+ I18n.load_path = []
81
+ I18n.backend = nil
82
+ super
83
+ end
73
84
 
74
- def store_translations(locale, data)
75
- I18n.backend.store_translations(locale, data)
76
- end
85
+ def store_translations(locale, data)
86
+ I18n.backend.store_translations(locale, data)
87
+ end
77
88
 
78
- def locales_dir
79
- File.dirname(__FILE__) + '/test_data/locales'
89
+ def locales_dir
90
+ "#{File.dirname(__FILE__)}/test_data/locales"
91
+ end
80
92
  end
81
93
  end