spec/ruby/i18n/js/segment_spec.rb in i18n-js-3.0.0.rc12 vs spec/ruby/i18n/js/segment_spec.rb in i18n-js-3.0.0.rc13
- old
+ new
@@ -4,11 +4,16 @@
let(:file) { "tmp/i18n-js/segment.js" }
let(:translations){ { en: { "test" => "Test" }, fr: { "test" => "Test2" } } }
let(:namespace) { "MyNamespace" }
let(:pretty_print){ nil }
- let(:options) { {namespace: namespace, pretty_print: pretty_print} }
+ let(:js_extend) { nil }
+ let(:sort_translation_keys){ nil }
+ let(:options) { { namespace: namespace,
+ pretty_print: pretty_print,
+ js_extend: js_extend,
+ sort_translation_keys: sort_translation_keys }.delete_if{|k,v| v.nil?} }
subject { I18n::JS::Segment.new(file, translations, options) }
describe ".new" do
it "should persist the file path variable" do
@@ -87,22 +92,65 @@
MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] || {}), {"test":"Test2"});
EOF
end
end
- context "when sort_translation_keys? is true" do
- before :each do
- I18n::JS.sort_translation_keys = true
+ context "when js_extend is true" do
+ let(:js_extend){ true }
+
+ let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
+
+ it 'should output the keys as sorted' do
+ file_should_exist "segment.js"
+
+ File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
+MyNamespace.translations || (MyNamespace.translations = {});
+MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
+ EOF
end
+ end
+ context "when js_extend is false" do
+ let(:js_extend){ false }
+
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
it 'should output the keys as sorted' do
file_should_exist "segment.js"
File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
MyNamespace.translations || (MyNamespace.translations = {});
+MyNamespace.translations["en"] = {"a":"Test","b":"Test"};
+ EOF
+ end
+ end
+
+ context "when sort_translation_keys is true" do
+ let(:sort_translation_keys){ true }
+
+ let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
+
+ it 'should output the keys as sorted' do
+ file_should_exist "segment.js"
+
+ File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
+MyNamespace.translations || (MyNamespace.translations = {});
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
+ EOF
+ end
+ end
+
+ context "when sort_translation_keys is false" do
+ let(:sort_translation_keys){ false }
+
+ let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
+
+ it 'should output the keys as sorted' do
+ file_should_exist "segment.js"
+
+ File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
+MyNamespace.translations || (MyNamespace.translations = {});
+MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"b":"Test","a":"Test"});
EOF
end
end
end
end