Skip to content

Commit

Permalink
clear cache on merge! too ...
Browse files Browse the repository at this point in the history
  • Loading branch information
doits committed Sep 8, 2016
1 parent 70e6249 commit e755bbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/i18n/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def clear

def merge!(val)
# see annotate hash below why whis must be done
clear_cache
val.select { |_, v| v.is_a?(Hash) }.each { |_, v| annotate_hash(v) }
super(val)
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_i18n_globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,16 @@ def test_that_cache_is_cleared_after_setting_a_new_global

assert_equal 'Hi there, Dobby!', I18n.translate('greeting')
end

def test_that_cache_is_cleared_after_merging_a_new_global
I18n.config.globals = {
name: 'Greg'
}

assert_equal 'Hi there, Greg!', I18n.translate('greeting')

I18n.config.globals.merge!(name: 'Dobby')

assert_equal 'Hi there, Dobby!', I18n.translate('greeting')
end
end

0 comments on commit e755bbe

Please sign in to comment.