Skip to content

Commit

Permalink
Merge pull request ruby-i18n#295 from davidcornu/nil-dup
Browse files Browse the repository at this point in the history
Don't try to duplicate nil options
  • Loading branch information
carlosantoniodasilva committed Jan 10, 2015
2 parents ee7fef8 + 886de11 commit f2c9c66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/i18n/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module Base
attr_reader :locale, :key, :options

def initialize(locale, key, options = nil)
@key, @locale, @options = key, locale, options.dup || {}
options = options && options.dup || {}
@key, @locale, @options = key, locale, options
options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
end

Expand Down
5 changes: 5 additions & 0 deletions test/i18n/exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def test_invalid_locale_stores_locale
end
end

test "MissingTranslation::Base#initialize can be called without options" do
exception = I18n::MissingTranslation.new(:en, 'foo')
assert_equal({}, exception.options)
end

test "MissingTranslationData exception stores locale, key and options" do
force_missing_translation_data do |exception|
assert_equal 'de', exception.locale
Expand Down

0 comments on commit f2c9c66

Please sign in to comment.