spec/i18n_js_spec.rb in i18n-js-3.0.0.rc7 vs spec/i18n_js_spec.rb in i18n-js-3.0.0.rc8
- old
+ new
@@ -71,14 +71,17 @@
it "exports with multiple conditions to a JS file per available locale" do
allow(::I18n).to receive(:available_locales){ [:en, :fr] }
set_config "multiple_conditions_per_locale.yml"
+ expected_locales = %w(en fr)
+
result = I18n::JS.translation_segments
- result.keys.should eql(["tmp/i18n-js/bits.en.js", "tmp/i18n-js/bits.fr.js"])
+ expected_files = expected_locales.map { |locale| "tmp/i18n-js/bits.#{locale}.js" }
+ result.keys.should eql(expected_files)
- %w{en fr}.each do |lang|
+ expected_locales.each do |lang|
result["tmp/i18n-js/bits.#{lang}.js"].keys.should eql([lang.to_sym])
result["tmp/i18n-js/bits.#{lang}.js"][lang.to_sym].keys.sort.should eql([:date, :number])
end
end
@@ -124,9 +127,71 @@
result[:en][:admin][:show][:title].should eql("Show")
result[:fr][:admin][:show][:title].should eql("Visualiser")
result[:en][:admin][:edit][:title].should eql("Edit")
result[:fr][:admin][:edit][:title].should eql("Editer")
+ end
+ end
+
+ context "fallbacks" do
+ it "exports without fallback when disabled" do
+ set_config "js_file_per_locale_without_fallbacks.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql(nil)
+ end
+
+ it "exports with default_locale as fallback when enabled" do
+ set_config "js_file_per_locale_with_fallbacks_enabled.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Success")
+ end
+
+ it "exports with default_locale as fallback when enabled with :default_locale" do
+ set_config "js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Success")
+ end
+
+ it "exports with given locale as fallback" do
+ set_config "js_file_per_locale_with_fallbacks_as_locale.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Erfolg")
+ end
+
+ context "with I18n::Fallbacks enabled" do
+ let(:backend_with_fallbacks) { backend_class_with_fallbacks.new }
+ let!(:old_backebad) { I18n.backend }
+
+ before do
+ I18n.backend = backend_with_fallbacks
+ I18n.fallbacks[:fr] = [:de, :en]
+ end
+ after { I18n.backend = old_backebad }
+
+ it "exports with defined locale as fallback when enabled" do
+ set_config "js_file_per_locale_with_fallbacks_enabled.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Erfolg")
+ end
+
+ it "exports with defined locale as fallback when enabled with :default_locale" do
+ set_config "js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Success")
+ end
+
+ it "exports with Fallbacks as Hash" do
+ set_config "js_file_per_locale_with_fallbacks_as_hash.yml"
+
+ result = I18n::JS.translation_segments
+ result["tmp/i18n-js/fr.js"][:fr][:fallback_test].should eql("Erfolg")
+ end
end
end
context "I18n.available_locales" do
context "when I18n.available_locales is not set" do