From 2b52e7a89119bd530a27abff8e63ee134c3630bb Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Tue, 24 Nov 2020 17:59:44 -0800 Subject: [PATCH] Rollback PR #2169 and bump 2.15.1 (#2203) * Rollback PR #2169 * Add changelog * Bump version to 2.15.1 --- CHANGELOG.md | 6 ++++++ Gemfile.lock | 2 +- lib/faker.rb | 29 +++-------------------------- lib/faker/version.rb | 2 +- test/test_locale.rb | 15 --------------- 5 files changed, 11 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dca6c8ec7..d295dcfd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [v2.15.1](https://github.com/faker-ruby/faker/tree/v2.15.1) (2020-11-24) + +- Rollback PR #2169 and bump 2.15.1 [#2203](https://github.com/faker-ruby/faker/pull/2203) @vbrazo + +------------------------------------------------------------------------------ + ## [v2.15.0](https://github.com/faker-ruby/faker/tree/v2.15.0) (2020-11-24) ## Bug/Fixes diff --git a/Gemfile.lock b/Gemfile.lock index ed81ce02e4..74db1dfa0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - faker (2.15.0) + faker (2.15.1) i18n (>= 1.6, < 2) GEM diff --git a/lib/faker.rb b/lib/faker.rb index e29ecde01b..49a8fd0406 100644 --- a/lib/faker.rb +++ b/lib/faker.rb @@ -8,27 +8,10 @@ Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file } -module Faker - @i18n_loaded = nil - - class << self - def load_i18n - return if @i18n_loaded - - if I18n.available_locales&.any? - # We expect all locale .yml files to have the locale name in its filename - I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}.yml")] - # Or to be located in a directory with the locale name - I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}/*.yml")] - else - I18n.load_path += ::Dir[::File.join(__dir__, 'locales', '**/*.yml')] - end - - I18n.reload! if I18n.backend.initialized? - @i18n_loaded = true - end - end +I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')] +I18n.reload! if I18n.backend.initialized? +module Faker module Config @locale = nil @random = nil @@ -37,8 +20,6 @@ class << self attr_writer :locale, :random def locale - Faker.load_i18n - # Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen @locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first) end @@ -168,8 +149,6 @@ def parse(key) # Call I18n.translate with our configured locale if no # locale is specified def translate(*args, **opts) - Faker.load_i18n - opts[:locale] ||= Faker::Config.locale opts[:raise] = true I18n.translate(*args, **opts) @@ -186,8 +165,6 @@ def translate(*args, **opts) # Executes block with given locale set. def with_locale(tmp_locale = nil, &block) - Faker.load_i18n - current_locale = Faker::Config.own_locale Faker::Config.locale = tmp_locale diff --git a/lib/faker/version.rb b/lib/faker/version.rb index 8b806b9480..5a995f9689 100644 --- a/lib/faker/version.rb +++ b/lib/faker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Faker #:nodoc: - VERSION = '2.15.0' + VERSION = '2.15.1' end diff --git a/test/test_locale.rb b/test/test_locale.rb index 102f7d7f02..2b91ca6105 100644 --- a/test/test_locale.rb +++ b/test/test_locale.rb @@ -78,19 +78,4 @@ def test_regex def test_available_locales assert I18n.locale_available?('en-GB') end - - def test_load_i18n - Faker.instance_variable_set :@i18n_loaded, nil - available_locales_was = I18n.available_locales - - I18n.available_locales = %i[en ja id] - Faker.load_i18n - I18n.eager_load! - - assert Faker.instance_variable_get(:@i18n_loaded) - assert_equal %i[en id ja], I18n.backend.translations.keys.sort - ensure - I18n.available_locales = available_locales_was - Faker.instance_variable_set :@i18n_loaded, nil - end end