-
Type:
Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The problem is that BigDecimal gets stored to database as a string, but when reading it does not get converted back to BigDecimal. This bug was introduced by commit 5286a42ae841fdb91d61. The following simple example fails:
class Product
include Mongoid::Document
field :price, :type => BigDecimal
field :vat_rate, :type => BigDecimal
def vat_rate_fraction
(self.vat_rate / 100.0) + 1.0
end
end
spec example:
describe Product do
it "calculates VAT inclusive price" do
product = Product.create(:price => 1999, :vat_rate => 20)
product.reload.vat_rate_fraction.should == BigDecimal.new('1.2')
end
end
fail:
Failures:
1) Product calculates VAT inclusive price
Failure/Error: product.reload.vat_rate_fraction.should == BigDecimal.new('1.2')
NoMethodError:
undefined method `/' for "20":String
- ./app/models/product.rb:7:in `vat_rate_fraction'
- ./spec/models/product_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.09278 seconds
1 example, 1 failure