Skip to content

Instantly share code, notes, and snippets.

@ichi
Created March 8, 2016 08:55
Show Gist options
  • Save ichi/1a33cce15cc086fbdbc0 to your computer and use it in GitHub Desktop.
Save ichi/1a33cce15cc086fbdbc0 to your computer and use it in GitHub Desktop.
Fakerのlocale設定無視
# config/initializers/faker.rb
if defined?(Faker)
module Faker
class Internet < Base
class << self
def user_name_with_ignoring_locale(specifier = nil, separators = %w(. _))
ignore_locale do
user_name_without_ignoring_locale(specifier, separators)
end
end
alias_method_chain :user_name, :ignoring_locale
def domain_word_with_ignoring_locale
ignore_locale do
domain_word_without_ignoring_locale
end
end
alias_method_chain :domain_word, :ignoring_locale
private
def ignore_locale
current_locale = Faker::Config.locale
Faker::Config.locale = nil
I18n.with_locale('en') do
yield
end
ensure
Faker::Config.locale = current_locale
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment