Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored spec with "loading a serialized Money via YAML" context. F…

…it comment to 80 col width.
  • Loading branch information...
commit 912c0239e9b2878774df2e65004d1ec7a1681f31 1 parent 61e5c72
Robert Starsi authored
Showing with 14 additions and 10 deletions.
  1. +4 −1 lib/money/money.rb
  2. +10 −9 spec/money_spec.rb
View
5 lib/money/money.rb
@@ -25,7 +25,10 @@ def fractional
if self.class.infinite_precision
@fractional
else
- # If the Money object is created from a serialized YAML string, @fractional can end up being set to a Float. We need to ensure it is BigDecimal before calling #round with two paramers. Float class only provides #round with 0 or 1 parameter.
+ # If the Money object is created from a serialized YAML string,
+ # @fractional can end up being set to a Float. We need to ensure
+ # it is BigDecimal before calling #round with two paramers.
+ # Float class only provides #round with 0 or 1 parameter.
BigDecimal.new(@fractional, 0).round(0, self.class.rounding_mode).to_i
end
end
View
19 spec/money_spec.rb
@@ -147,9 +147,9 @@ def expectation.fractional
end
end
- it "when loading a serialized Money object from YAML fractional rounding always works on bigdecimal" do
- # Loading a YAML serialized money object is a common use case when dealing with persisting the money object in a queue, for example delayed_job
- serialized = <<YAML
+ context "loading a serialized Money via YAML" do
+ it "uses BigDecimal when rounding" do
+ serialized = <<YAML
!ruby/object:Money
fractional: 249.5
currency: !ruby/object:Money::Currency
@@ -167,13 +167,14 @@ def expectation.fractional
thousands_separator: .
iso_numeric: '978'
mutex: !ruby/object:Mutex {}
- last_updated: 2012-11-23 20:41:47.454438399 +02:00
+ last_updated: 2012-11-23 20:41:47.454438399 +02:00
YAML
- m = YAML::load serialized
- m.should be_a(Money)
- m.class.infinite_precision.should == false
- m.fractional.should == 250 # 249.5 rounded up
- m.fractional.should be_a(Integer)
+ m = YAML::load serialized
+ m.should be_a(Money)
+ m.class.infinite_precision.should == false
+ m.fractional.should == 250 # 249.5 rounded up
+ m.fractional.should be_a(Integer)
+ end
end
context "user changes rounding_mode" do

0 comments on commit 912c023

Please sign in to comment.
Something went wrong with that request. Please try again.