Skip to content

Commit 5d1b645

Browse files
Merge pull request #23 from frantisekrokusekpa/master
fix travis, ruby warnings and random failling spec
2 parents d146557 + a33f2dd commit 5d1b645

File tree

8 files changed

+18
-38
lines changed

8 files changed

+18
-38
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ rvm:
44
gemfile:
55
- test/gemfiles/Gemfile.rails-4.2.x
66
- test/gemfiles/Gemfile.rails-5.0.x
7+
- test/gemfiles/Gemfile.rails-6.0.x
78
env:
89
- DB=mysql
910
- DB=postgres

lib/json_translate/translates.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def translates(*attrs, allow_blank: false)
3030
normalized_locale = locale.to_s.downcase.gsub(/[^a-z]/, '')
3131

3232
define_method :"#{attr_name}_#{normalized_locale}" do |**params|
33-
read_json_translation(attr_name, locale, false, **params)
33+
read_json_translation(attr_name, locale: locale, fallback: false, **params)
3434
end
3535

3636
define_method "#{attr_name}_#{normalized_locale}=" do |value|
37-
write_json_translation(attr_name, value, locale, allow_blank: allow_blank)
37+
write_json_translation(attr_name, value, locale: locale, allow_blank: allow_blank)
3838
end
3939
end
4040

lib/json_translate/translates/instance_methods.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def json_translate_fallback_locales(locale)
2323
end
2424
end
2525

26-
def read_json_translation(attr_name, locale = I18n.locale, fallback = true, **params)
26+
def read_json_translation(attr_name, locale: I18n.locale, fallback: true, **params)
2727
translations = public_send("#{attr_name}#{SUFFIX}") || {}
2828

2929
selected_locale = locale
@@ -45,7 +45,7 @@ def read_json_translation(attr_name, locale = I18n.locale, fallback = true, **pa
4545
translation
4646
end
4747

48-
def write_json_translation(attr_name, value, locale = I18n.locale, allow_blank: false)
48+
def write_json_translation(attr_name, value, locale: I18n.locale, allow_blank:)
4949
value = allow_blank ? value : value.presence
5050
translation_store = "#{attr_name}#{SUFFIX}"
5151
translations = public_send(translation_store) || {}

lib/json_translate/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module JSONTranslate
2-
VERSION = "4.0.0"
2+
VERSION = "4.0.1"
33
end

test/gemfiles/Gemfile.rails-5.0.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22
gemspec :path => './../..'
33

4-
gem 'pg', '< 1.0.0'
4+
gem 'pg', '~> 1.0.0'
55
gem 'mysql2'
66
gem 'activerecord', '~> 5.0.0'

test/gemfiles/Gemfile.rails-6.0.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
gemspec :path => './../..'
3+
4+
gem 'pg'
5+
gem 'mysql2'
6+
gem 'activerecord'

test/test_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def establish_connection(config)
4040
end
4141

4242
def create_database
43-
system_config = db_config
44-
connection = establish_connection(system_config)
43+
connection = establish_connection(db_config)
4544
connection.create_database(db_config['database']) rescue nil
4645
end
4746

@@ -61,6 +60,8 @@ def create_table
6160
def setup
6261
I18n.available_locales = ['en', 'en-US', 'fr']
6362
I18n.config.enforce_available_locales = true
63+
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
64+
I18n.fallbacks = I18n.available_locales
6465
DatabaseCleaner.start
6566
end
6667

test/translates_test.rb

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ def test_assigns_in_current_locale
1313
def test_retrieves_in_current_locale
1414
p = Post.new(
1515
:title_translations => { "en" => "English Title", "fr" => "Titre français" },
16-
:body_1_translations => { "en" => "English Body", "fr" => "Corps anglais" }
16+
:body_1_translations => { "en" => "English Body", "fr" => "Corps français" }
1717
)
1818
I18n.with_locale(:fr) do
1919
assert_equal("Titre français", p.title)
20-
assert_equal("Corps anglais", p.body_1)
20+
assert_equal("Corps français", p.body_1)
2121
end
2222
end
2323

2424
def test_retrieves_in_current_locale_with_fallbacks
25-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
26-
I18n.default_locale = :"en-US"
27-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
28-
2925
p = Post.new(:title_translations => {"en" => "English Title"}, :body_1_translations => { "en" => "English Body" })
3026
I18n.with_locale(:fr) do
3127
assert_equal("English Title", p.title)
@@ -90,10 +86,6 @@ def test_retrieves_in_specified_locale
9086
end
9187

9288
def test_retrieves_in_specified_locale_with_fallbacks
93-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
94-
I18n.default_locale = :"en-US"
95-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
96-
9789
p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
9890
I18n.with_locale(:fr) do
9991
assert_equal("English Title", p.title)
@@ -106,10 +98,6 @@ def test_retrieves_in_specified_locale_with_fallbacks
10698
end
10799

108100
def test_fallback_from_empty_string
109-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
110-
I18n.default_locale = :"en-US"
111-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
112-
113101
p = Post.new(:title_translations => { "en" => "English Title", "fr" => "" }, :body_1_translations => { "en" => "English Body", "fr" => "" })
114102
I18n.with_locale(:fr) do
115103
assert_equal("English Title", p.title)
@@ -122,10 +110,6 @@ def test_fallback_from_empty_string
122110
end
123111

124112
def test_retrieves_in_specified_locale_with_fallback_disabled
125-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
126-
I18n.default_locale = :"en-US"
127-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
128-
129113
p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
130114
p.disable_fallback
131115
I18n.with_locale(:fr) do
@@ -135,10 +119,6 @@ def test_retrieves_in_specified_locale_with_fallback_disabled
135119
end
136120

137121
def test_retrieves_in_specified_locale_with_fallback_disabled_using_a_block
138-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
139-
I18n.default_locale = :"en-US"
140-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
141-
142122
p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
143123
p.enable_fallback
144124

@@ -163,10 +143,6 @@ def test_retrieves_in_specified_locale_with_fallback_disabled_using_a_block
163143
end
164144

165145
def test_retrieves_in_specified_locale_with_fallback_reenabled
166-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
167-
I18n.default_locale = :"en-US"
168-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
169-
170146
p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
171147
p.disable_fallback
172148
p.enable_fallback
@@ -181,10 +157,6 @@ def test_retrieves_in_specified_locale_with_fallback_reenabled
181157
end
182158

183159
def test_retrieves_in_specified_locale_with_fallback_reenabled_using_a_block
184-
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
185-
I18n.default_locale = :"en-US"
186-
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")
187-
188160
p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
189161
p.disable_fallback
190162

0 commit comments

Comments
 (0)