Skip to content

Commit

Permalink
Merge pull request #23 from frantisekrokusekpa/master
Browse files Browse the repository at this point in the history
fix travis, ruby warnings and random failling spec
  • Loading branch information
frantisekrokusek authored Apr 22, 2021
2 parents d146557 + a33f2dd commit 5d1b645
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 38 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ rvm:
gemfile:
- test/gemfiles/Gemfile.rails-4.2.x
- test/gemfiles/Gemfile.rails-5.0.x
- test/gemfiles/Gemfile.rails-6.0.x
env:
- DB=mysql
- DB=postgres
Expand Down
4 changes: 2 additions & 2 deletions lib/json_translate/translates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def translates(*attrs, allow_blank: false)
normalized_locale = locale.to_s.downcase.gsub(/[^a-z]/, '')

define_method :"#{attr_name}_#{normalized_locale}" do |**params|
read_json_translation(attr_name, locale, false, **params)
read_json_translation(attr_name, locale: locale, fallback: false, **params)
end

define_method "#{attr_name}_#{normalized_locale}=" do |value|
write_json_translation(attr_name, value, locale, allow_blank: allow_blank)
write_json_translation(attr_name, value, locale: locale, allow_blank: allow_blank)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/json_translate/translates/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def json_translate_fallback_locales(locale)
end
end

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

selected_locale = locale
Expand All @@ -45,7 +45,7 @@ def read_json_translation(attr_name, locale = I18n.locale, fallback = true, **pa
translation
end

def write_json_translation(attr_name, value, locale = I18n.locale, allow_blank: false)
def write_json_translation(attr_name, value, locale: I18n.locale, allow_blank:)
value = allow_blank ? value : value.presence
translation_store = "#{attr_name}#{SUFFIX}"
translations = public_send(translation_store) || {}
Expand Down
2 changes: 1 addition & 1 deletion lib/json_translate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JSONTranslate
VERSION = "4.0.0"
VERSION = "4.0.1"
end
2 changes: 1 addition & 1 deletion test/gemfiles/Gemfile.rails-5.0.x
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
gemspec :path => './../..'

gem 'pg', '< 1.0.0'
gem 'pg', '~> 1.0.0'
gem 'mysql2'
gem 'activerecord', '~> 5.0.0'
6 changes: 6 additions & 0 deletions test/gemfiles/Gemfile.rails-6.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'
gemspec :path => './../..'

gem 'pg'
gem 'mysql2'
gem 'activerecord'
5 changes: 3 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def establish_connection(config)
end

def create_database
system_config = db_config
connection = establish_connection(system_config)
connection = establish_connection(db_config)
connection.create_database(db_config['database']) rescue nil
end

Expand All @@ -61,6 +60,8 @@ def create_table
def setup
I18n.available_locales = ['en', 'en-US', 'fr']
I18n.config.enforce_available_locales = true
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.fallbacks = I18n.available_locales
DatabaseCleaner.start
end

Expand Down
32 changes: 2 additions & 30 deletions test/translates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ def test_assigns_in_current_locale
def test_retrieves_in_current_locale
p = Post.new(
:title_translations => { "en" => "English Title", "fr" => "Titre français" },
:body_1_translations => { "en" => "English Body", "fr" => "Corps anglais" }
:body_1_translations => { "en" => "English Body", "fr" => "Corps français" }
)
I18n.with_locale(:fr) do
assert_equal("Titre français", p.title)
assert_equal("Corps anglais", p.body_1)
assert_equal("Corps français", p.body_1)
end
end

def test_retrieves_in_current_locale_with_fallbacks
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => {"en" => "English Title"}, :body_1_translations => { "en" => "English Body" })
I18n.with_locale(:fr) do
assert_equal("English Title", p.title)
Expand Down Expand Up @@ -90,10 +86,6 @@ def test_retrieves_in_specified_locale
end

def test_retrieves_in_specified_locale_with_fallbacks
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
I18n.with_locale(:fr) do
assert_equal("English Title", p.title)
Expand All @@ -106,10 +98,6 @@ def test_retrieves_in_specified_locale_with_fallbacks
end

def test_fallback_from_empty_string
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title", "fr" => "" }, :body_1_translations => { "en" => "English Body", "fr" => "" })
I18n.with_locale(:fr) do
assert_equal("English Title", p.title)
Expand All @@ -122,10 +110,6 @@ def test_fallback_from_empty_string
end

def test_retrieves_in_specified_locale_with_fallback_disabled
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
p.disable_fallback
I18n.with_locale(:fr) do
Expand All @@ -135,10 +119,6 @@ def test_retrieves_in_specified_locale_with_fallback_disabled
end

def test_retrieves_in_specified_locale_with_fallback_disabled_using_a_block
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
p.enable_fallback

Expand All @@ -163,10 +143,6 @@ def test_retrieves_in_specified_locale_with_fallback_disabled_using_a_block
end

def test_retrieves_in_specified_locale_with_fallback_reenabled
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
p.disable_fallback
p.enable_fallback
Expand All @@ -181,10 +157,6 @@ def test_retrieves_in_specified_locale_with_fallback_reenabled
end

def test_retrieves_in_specified_locale_with_fallback_reenabled_using_a_block
I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.default_locale = :"en-US"
I18n.fallbacks = I18n::Locale::Fallbacks.new(fr: :"en-US")

p = Post.new(:title_translations => { "en" => "English Title" }, :body_1_translations => { "en" => "English Body" })
p.disable_fallback

Expand Down

0 comments on commit 5d1b645

Please sign in to comment.