forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed translation fallbacks in ruby 1.8
- Loading branch information
Showing
2 changed files
with
24 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
require "test/unit" | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
require "faker" | ||
LoadedYaml = ['en', 'en-bork'].inject({}) do |h, locale| | ||
h[locale] = YAML.load_file(File.expand_path(File.dirname(__FILE__) + "/../lib/locales/#{locale}.yml"))[locale]['faker'] | ||
h | ||
end | ||
|
||
class TestLocale < Test::Unit::TestCase | ||
def test_case_name | ||
def test_locale_separate_from_i18n | ||
I18n.locale = :en | ||
Faker::Config.locale = :de | ||
assert Faker::PhoneNumber.phone_number.match(/\(0\d+\) \d+|\+49-\d+-\d+/) | ||
assert Faker::Address.street_name.match(//) | ||
end | ||
|
||
def test_configured_locale_translation | ||
Faker::Config.locale = 'en-bork' | ||
assert_equal Faker::Base.translate('faker.lorem.words').first, LoadedYaml['en-bork']['lorem']['words'].first | ||
end | ||
|
||
def test_locale_override_when_calling_translate | ||
Faker::Config.locale = 'en-bork' | ||
assert_equal Faker::Base.translate('faker.lorem.words', :locale => :en).first, LoadedYaml['en']['lorem']['words'].first | ||
end | ||
|
||
def test_translation_fallback | ||
Faker::Config.locale = 'en-bork' | ||
assert_nil LoadedYaml['en-bork']['name'] | ||
assert_equal Faker::Base.translate('faker.name.first_name').first, LoadedYaml['en']['name']['first_name'].first | ||
end | ||
end | ||
|
||
# formats: ['(0###) #########', '(0####) #######', '+49-###-#######', '+49-####-########'] |