spec/i18n_js_spec.rb in i18n-js-3.0.0.rc5 vs spec/i18n_js_spec.rb in i18n-js-3.0.0.rc6
- old
+ new
@@ -49,10 +49,24 @@
set_config "multiple_conditions.yml"
I18n::JS.export
file_should_exist "bitsnpieces.js"
end
+
+ 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"
+
+ result = I18n::JS.translation_segments
+ result.keys.should eql(["tmp/i18n-js/bits.en.js", "tmp/i18n-js/bits.fr.js"])
+
+ %w{en fr}.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
end
context "filters" do
it "filters translations using scope *.date.formats" do
result = I18n::JS.filter(translations, "*.date.formats")
@@ -91,17 +105,48 @@
result[:en][:admin][:edit][:title].should eql("Edit")
result[:fr][:admin][:edit][:title].should eql("Editer")
end
end
+ context "I18n.available_locales" do
+ context "when I18n.available_locales is not set" do
+ it "should allow all locales" do
+ result = I18n::JS.scoped_translations("*.admin.*.title")
+
+ result[:en][:admin][:show][:title].should eql("Show")
+ result[:fr][:admin][:show][:title].should eql("Visualiser")
+ result[:ja][:admin][:show][:title].should eql("Ignore me")
+ end
+ end
+
+ context "when I18n.available_locales is set" do
+ before { allow(::I18n).to receive(:available_locales){ [:en, :fr] } }
+
+ it "should ignore non-valid locales" do
+ result = I18n::JS.scoped_translations("*.admin.*.title")
+
+ result[:en][:admin][:show][:title].should eql("Show")
+ result[:fr][:admin][:show][:title].should eql("Visualiser")
+ result.keys.include?(:ja).should eql(false)
+ end
+ end
+ end
+
context "general" do
it "sets export directory" do
I18n::JS.export_dir.should eql("public/javascripts")
end
it "sets empty hash as configuration when no file is found" do
- I18n::JS.config?.should be_false
+ I18n::JS.config?.should eql(false)
I18n::JS.config.should eql({})
+ end
+
+ it "executes erb in config file" do
+ set_config "erb.yml"
+
+ config_entry = I18n::JS.config["translations"].first
+ config_entry["only"].should eq("*.date.formats")
end
end
context "hash merging" do
it "performs a deep merge" do