test/backend/chain_test.rb in i18n-0.7.0.beta1 vs test/backend/chain_test.rb in i18n-0.7.0
- old
+ new
@@ -2,14 +2,24 @@
class I18nBackendChainTest < I18n::TestCase
def setup
super
@first = backend(:en => {
- :foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }, :dates => {:a => "A"}
+ :foo => 'Foo', :formats => {
+ :short => 'short',
+ :subformats => {:short => 'short'},
+ },
+ :plural_1 => { :one => '%{count}' },
+ :dates => {:a => "A"}
})
@second = backend(:en => {
- :bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }, :dates => {:a => "B", :b => "B"}
+ :bar => 'Bar', :formats => {
+ :long => 'long',
+ :subformats => {:long => 'long'},
+ },
+ :plural_2 => { :one => 'one' },
+ :dates => {:a => "B", :b => "B"}
})
@chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
end
test "looks up translations from the first chained backend" do
@@ -37,15 +47,15 @@
test 'default is returned if translation is missing' do
assert_equal({}, I18n.t(:'i18n.transliterate.rule', :locale => 'en', :default => {}))
end
- test "namespace lookup collects results from all backends" do
- assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
+ test "namespace lookup collects results from all backends and merges deep hashes" do
+ assert_equal({:long=>"long", :subformats=>{:long=>"long", :short=>"short"}, :short=>"short"}, I18n.t(:formats))
end
- test "namespace lookup collects results from all backends and does not overwrite" do
+ test "namespace lookup collects results from all backends and lets leftmost backend take priority" do
assert_equal({ :a => "A", :b => "B" }, I18n.t(:dates))
end
test "namespace lookup with only the first backend returning a result" do
assert_equal({ :one => '%{count}' }, I18n.t(:plural_1))
@@ -57,10 +67,14 @@
end
test "bulk lookup collects results from all backends" do
assert_equal ['Foo', 'Bar'], I18n.t([:foo, :bar])
assert_equal ['Foo', 'Bar', 'Bah'], I18n.t([:foo, :bar, :bah], :default => 'Bah')
- assert_equal [{ :short => 'short', :long => 'long' }, { :one => 'one' }, 'Bah'], I18n.t([:formats, :plural_2, :bah], :default => 'Bah')
+ assert_equal [{
+ :long=>"long",
+ :subformats=>{:long=>"long", :short=>"short"},
+ :short=>"short"}, {:one=>"one"},
+ "Bah"], I18n.t([:formats, :plural_2, :bah], :default => 'Bah')
end
test "store_translations options are not dropped while transfering to backend" do
@first.expects(:store_translations).with(:foo, {:bar => :baz}, {:option => 'persists'})
I18n.backend.store_translations :foo, {:bar => :baz}, {:option => 'persists'}