Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AmineAffifSkello
Andreas Loupasakis
Andrei
Andrei Andriichuk
Andrew Stellman
Andrew White
Andrius Chamentauskas
Anthony Hristov
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fix `Money#/` on an instance of a `Money` subclass treating a plain `Money` divisor as a number, so it returned a `Money` instead of the documented `Float`
- Fix `Money::Allocation.generate` converting a Rational with unlimited `to_d` precision. It now uses `Money.conversion_precision`
- Fix `Money::Currency.reset!` keeping the cached key set, so a currency registered before the reset was still accepted by `Money::Currency.new` and raised `NoMethodError` instead of `UnknownCurrency`
- Fix `Money::Bank::VariableExchange#import_rates` parsing `:json` with `JSON.load`, which instantiates any class named by a `json_class` key; it now uses `JSON.parse`
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money/arithmetic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def *(other)
# Money.new(100) / Money.new(10) #=> 10.0
#
def /(other)
if other.is_a?(self.class)
if other.is_a?(Money)
exchanged = other.exchange_to(currency)
raise ZeroDivisionError, "divided by Money(0)" if exchanged.zero?

Expand Down
7 changes: 7 additions & 0 deletions spec/money/arithmetic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@
expect(special_money_class.new(10_00, "USD") / 2).to be_a special_money_class
end

it "returns a Float when dividing a subclass of Money by a Money" do
special_money_class = Class.new(Money)
ratio = special_money_class.new(10_00, "USD") / Money.new(1_00, "USD")
expect(ratio).to be_a Float
expect(ratio).to eq 10.0
end

describe "rounding preference" do
before do
allow(Money).to receive(:rounding_mode).and_return(rounding_mode)
Expand Down