Permalink
Browse files

Merge pull request #66 from Locale/fix_default_being_array

Fix bug when :default is an array
  • Loading branch information...
2 parents 57b390d + 1225433 commit 748817216e9be0af9d5a6f674a9827398c80fe99 @tigrish tigrish committed Oct 9, 2012
Showing with 22 additions and 1 deletion.
  1. +6 −1 lib/localeapp/default_value_handler.rb
  2. +16 −0 spec/localeapp/default_value_handler_spec.rb
@@ -3,7 +3,12 @@ module I18n::Backend::Base
def default(locale, object, subject, options = {})
result = default_without_handler(locale, object, subject, options)
- Localeapp.missing_translations.add(locale, object, subject, options)
+ case subject # case is what i18n gem uses here so doing the same
+ when Array
+ Localeapp.missing_translations.add(locale, object, result, options)
+ else
+ Localeapp.missing_translations.add(locale, object, subject, options)
+ end
return result
end
end
@@ -13,4 +13,20 @@ class Klass
klass.default(:en, 'foo', 'bar', :baz => 'bam')
end
end
+
+ describe "when subject is an array" do
+ it "uses result of default call instead of array" do
+ with_configuration(:sending_environments => ['my_env'], :environment_name => 'my_env' ) do
+ Localeapp.missing_translations.should_receive(:add).with(:en, 'foo', 'not missing', :baz => 'bam')
+ I18n.stub!(:translate) do |subject, _|
+ if subject == :not_missing
+ "not missing"
+ else
+ nil
+ end
+ end
+ klass.default(:en, 'foo', [:missing, :not_missing], :baz => 'bam')
+ end
+ end
+ end
end

0 comments on commit 7488172

Please sign in to comment.