with_tax_included_in_price handles exceptions gracefully

This commit is contained in:
Rohan Mitchell
2015-11-04 15:32:31 +11:00
parent 8e1bade355
commit f499dd627a
2 changed files with 10 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ module Spree
result = yield
# TODO: ensure
ensure
self.included_in_price = old_included_in_price
calculator.calculable.included_in_price = old_included_in_price

View File

@@ -56,6 +56,15 @@ module Spree
tax_rate.included_in_price.should be_false
tax_rate.calculator.calculable.included_in_price.should be_false
end
it "restores both values when an exception is raised" do
expect do
tax_rate.send(:with_tax_included_in_price) { raise Exception.new 'oops' }
end.to raise_error 'oops'
tax_rate.included_in_price.should be_false
tax_rate.calculator.calculable.included_in_price.should be_false
end
end
end
end