Skip to content

Commit

Permalink
Merge pull request #1 from bforma/bug/ensure-delocalization-is-reset
Browse files Browse the repository at this point in the history
Ensure enable_delocalization is properly reset
  • Loading branch information
FabioMR committed Apr 10, 2014
2 parents 13e9306 + 99e0112 commit 37c053a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/delocalize/i18n_ext.rb
Expand Up @@ -16,15 +16,21 @@ def delocalization_disabled?
def with_delocalization_disabled(&block)
old_value = I18n.enable_delocalization
I18n.enable_delocalization = false
yield
I18n.enable_delocalization = old_value
begin
yield
ensure
I18n.enable_delocalization = old_value
end
end

def with_delocalization_enabled(&block)
old_value = I18n.enable_delocalization
I18n.enable_delocalization = true
yield
I18n.enable_delocalization = old_value
begin
yield
ensure
I18n.enable_delocalization = old_value
end
end
end
end
end
16 changes: 16 additions & 0 deletions test/delocalize_test.rb
Expand Up @@ -147,6 +147,14 @@ def teardown
end
end

test "properly resets when an error is raised in a with_delocalization_disabled block" do
I18n.enable_delocalization = true
I18n.with_delocalization_disabled do
raise 'error'
end rescue nil
assert_equal true, I18n.enable_delocalization
end

test "uses localized parsing if called with with_delocalization_enabled" do
I18n.with_delocalization_enabled do
@product.price = '1.299,99'
Expand All @@ -157,6 +165,14 @@ def teardown
end
end

test "properly resets when an error is raised in a with_delocalization_enabled block" do
I18n.enable_delocalization = false
I18n.with_delocalization_enabled do
raise 'error'
end rescue nil
assert_equal false, I18n.enable_delocalization
end

test "dirty attributes must detect changes in decimal columns" do
@product.price = 10
@product.save
Expand Down

0 comments on commit 37c053a

Please sign in to comment.