Commit 6da0e41
Changed files (3)
app
models
spec
features
models
app/models/quantity.rb
@@ -15,8 +15,8 @@ class Quantity
end
def eql?(other, delta = 0.1)
- converted = other.to(unit)
- (self.amount - converted.amount).abs <= delta
+ converted = other.respond_to?(:to) ? other.to(unit).amount : other
+ (self.amount - converted).abs <= delta
end
def to_s
spec/features/workouts_spec.rb
@@ -27,7 +27,7 @@ feature "Workouts", type: :feature do
subject.click_start
expect(user.workouts.count).to eql(1)
+ expect(user.workouts.last.body_weight).to eql(225.0)
end
-
end
end
spec/models/quantity_spec.rb
@@ -41,5 +41,16 @@ describe Quantity do
other = Quantity.new(61.2, :kgs)
expect(quantity).to eql(other)
end
+
+ it 'is equal to a float' do
+ quantity = Quantity.new(135.0, :lbs)
+ expect(quantity).to eql(135.0)
+ end
+
+ it 'is not equal' do
+ quantity = Quantity.new(135.0, :lbs)
+ other = Quantity.new(135.2, :lbs)
+ expect(quantity).to_not eql(other)
+ end
end
end