-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Faker localization for rake tasks
Was breaking rake db:seed file
- Loading branch information
Showing
7 changed files
with
142 additions
and
23 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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe LocaleFormatter do | ||
|
||
context "#format" do | ||
|
||
subject { LocaleFormatter.new('en_GB').format } | ||
|
||
it "defaults to :i18n" do | ||
expect(subject).to eql(:i18n) | ||
end | ||
|
||
end | ||
|
||
describe "#string" do | ||
|
||
context "when format is :i18n" do | ||
|
||
subject { LocaleFormatter.new(locale_string, format: format).string } | ||
|
||
let(:locale_string) { 'HH_xx' } | ||
|
||
let!(:format) { :i18n } | ||
|
||
it "forces the hyphenated format" do | ||
expect(subject).to eql("hh-XX") | ||
end | ||
|
||
it "downcases the language component" do | ||
expect(subject).to start_with('hh') | ||
end | ||
|
||
it "upcases the region" do | ||
expect(subject).to end_with('XX') | ||
end | ||
|
||
end | ||
|
||
context "when format is :fast_gettext" do | ||
|
||
subject { LocaleFormatter.new(locale_string, format: format).string } | ||
|
||
let(:locale_string) { 'HH-xx' } | ||
|
||
let!(:format) { :fast_gettext } | ||
|
||
it "forces the underescore format" do | ||
expect(subject).to eql("hh_XX") | ||
end | ||
|
||
it "downcases the language component" do | ||
expect(subject).to start_with('hh') | ||
end | ||
|
||
it "upcases the region" do | ||
expect(subject).to end_with('XX') | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe LocaleSet do | ||
|
||
describe "#for" do | ||
|
||
subject { LocaleSet.new(['en_gb', 'EN-US', :es, :fr]).for(format) } | ||
|
||
let!(:format) { :i18n } | ||
|
||
it "converts each item to a string" do | ||
subject.each do |item| | ||
expect(item).to be_a(String) | ||
end | ||
end | ||
|
||
it "removes duplicate items" do | ||
@locale_set = LocaleSet.new([:es, :es]) | ||
expect(@locale_set).to have(1).item | ||
end | ||
|
||
context "when format is :i18n" do | ||
|
||
let!(:format) { :i18n } | ||
|
||
it "returns each item in i18n format" do | ||
expect(subject).to eql(['en-GB', 'en-US', 'es', 'fr']) | ||
end | ||
|
||
end | ||
|
||
context "when format is :fast_gettext" do | ||
|
||
let!(:format) { :fast_gettext } | ||
|
||
it "returns each item in fast_gettext format" do | ||
expect(subject).to eql(['en_GB', 'en_US', 'es', 'fr']) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
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,11 +1,12 @@ | ||
require 'faker' | ||
|
||
LOCALE = 'en-GB' | ||
# Keep this as :en. Faker doesn't have :en-GB | ||
LOCALE = 'en' | ||
|
||
RSpec.configure do |config| | ||
config.before(:each) do | ||
I18n.locale = LOCALE | ||
Faker::Config.locale = LOCALE | ||
FastGettext.default_locale = LOCALE | ||
I18n.locale = LocaleFormatter.new(LOCALE, format: :i18n).to_s | ||
Faker::Config.locale = LocaleFormatter.new(LOCALE, format: :i18n).to_s | ||
FastGettext.default_locale = LocaleFormatter.new(LOCALE, format: :fast_gettext).to_s | ||
end | ||
end |