Skip to content
Merged
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
43 changes: 0 additions & 43 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/money/bank/variable_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def import_rates(format, s, opts = {})

if format == :ruby
warn '[WARNING] Using :ruby format when importing rates is potentially unsafe and ' \
'might lead to remote code execution via Marshal.load deserializer. Consider using ' \
'safe alternatives such as :json and :yaml.'
'might lead to remote code execution via Marshal.load deserializer. Consider using ' \
'safe alternatives such as :json and :yaml.'
end

store.transaction do
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def to_nearest_cash_value
smallest_denomination = as_d(self.currency.smallest_denomination)
rounded_value =
(fractional / smallest_denomination)
.round(0, self.class.rounding_mode) * smallest_denomination
.round(0, self.class.rounding_mode) * smallest_denomination

dup_with(fractional: return_value(rounded_value))
end
Expand Down
6 changes: 3 additions & 3 deletions lib/money/money/arithmetic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def eql?(other_money)
if other_money.is_a?(Money)
if !Money.strict_eql_compare && fractional == 0 && other_money.fractional == 0
warn "[DEPRECATION] Comparing 0 #{currency} with 0 " \
"#{other_money.currency} using `#eql?` will return false in " \
"future versions of Money. Opt-in to the new behavior by " \
"setting `Money.strict_eql_compare = true`."
"#{other_money.currency} using `#eql?` will return false in " \
"future versions of Money. Opt-in to the new behavior by " \
"setting `Money.strict_eql_compare = true`."
return true
end

Expand Down
40 changes: 20 additions & 20 deletions spec/currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def to_s
expect(described_class.find_by_iso_numeric(250)).to be_nil

described_class.register(
priority: 1,
iso_code: "FRF",
iso_numeric: "250",
name: "French Francs",
symbol: "FR",
subunit: "Centimes",
subunit_to_unit: 100,
decimal_mark: ",",
priority: 1,
iso_code: "FRF",
iso_numeric: "250",
name: "French Francs",
symbol: "FR",
subunit: "Centimes",
subunit_to_unit: 100,
decimal_mark: ",",
thousands_separator: " ",
)

Expand All @@ -94,12 +94,12 @@ def to_s

it "returns nil for unregistered currencies after cache invalidation" do
described_class.register(
priority: 1,
iso_code: "FRF",
iso_numeric: "250",
name: "French Francs",
symbol: "FR",
subunit: "Centimes",
priority: 1,
iso_code: "FRF",
iso_numeric: "250",
name: "French Francs",
symbol: "FR",
subunit: "Centimes",
subunit_to_unit: 100,
)

Expand Down Expand Up @@ -472,13 +472,13 @@ def to_s
cad = described_class.find(:cad)

described_class.register(
:priority => 100,
:iso_code => cad.iso_code,
:name => cad.name,
:subunit => cad.subunit,
:subunit_to_unit => cad.subunit_to_unit,
:priority => 100,
:iso_code => cad.iso_code,
:name => cad.name,
:subunit => cad.subunit,
:subunit_to_unit => cad.subunit_to_unit,
:thousands_separator => cad.thousands_separator,
:decimal_mark => modified_mark,
:decimal_mark => modified_mark,
)
end

Expand Down
24 changes: 14 additions & 10 deletions spec/money/allocation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
# Rounding due to inconsistent BigDecimal size in ruby compared to jruby. In reality the
# first 2 elements will look like the last one with a '5' at the end, compensating for a
# missing fraction
expect(parts.map { |x| x.round(10) }).to eq([
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
])
expect(parts.map { |x| x.round(10) }).to eq(
[
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
],
)
expect(parts.inject(0, :+)).to eq(amount)
end
end
Expand Down Expand Up @@ -123,11 +125,13 @@
# Rounding due to inconsistent BigDecimal size in ruby compared to jruby. In reality the
# first 2 elements will look like the last one with a '5' at the end, compensating for a
# missing fraction
expect(parts.map { |x| x.round(10) }).to eq([
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
])
expect(parts.map { |x| x.round(10) }).to eq(
[
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
],
)
expect(parts.inject(0, :+)).to eq(amount)
end
end
Expand Down
112 changes: 56 additions & 56 deletions spec/money/arithmetic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@
describe "#div" do
it "divides Money by Integer and returns Money" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(3, :USD) },
{ a: Money.new(13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(3, :USD) },
]
ts.each do |t|
expect(t[:a].div(t[:b])).to eq t[:c]
Expand All @@ -481,10 +481,10 @@

it "divides Money by Money (same currency) and returns Float" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: 3.25 },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: -3.25 },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: -3.25 },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25 },
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: 3.25 },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: -3.25 },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: -3.25 },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25 },
]
ts.each do |t|
expect(t[:a].div(t[:b])).to eq t[:c]
Expand All @@ -493,10 +493,10 @@

it "divides Money by Money (different currency) and returns Float" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: 1.625 },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: -1.625 },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: -1.625 },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625 },
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: 1.625 },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: -1.625 },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: -1.625 },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625 },
]
ts.each do |t|
expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
Expand All @@ -522,10 +522,10 @@
describe "#divmod" do
it "calculates division and modulo with Integer" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] },
{ a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] },
]
ts.each do |t|
expect(t[:a].divmod(t[:b])).to eq t[:c]
Expand All @@ -534,10 +534,10 @@

it "calculates division and modulo with Money (same currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: [3, Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: [-4, Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: [-4, Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: [3, Money.new(-1, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: [3, Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: [-4, Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: [-4, Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: [3, Money.new(-1, :USD)] },
]
ts.each do |t|
expect(t[:a].divmod(t[:b])).to eq t[:c]
Expand All @@ -546,10 +546,10 @@

it "calculates division and modulo with Money (different currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: [1, Money.new(5, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: [-2, Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: [-2, Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: [1, Money.new(-5, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: [1, Money.new(5, :USD)] },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: [-2, Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: [-2, Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: [1, Money.new(-5, :USD)] },
]
ts.each do |t|
expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
Expand All @@ -560,10 +560,10 @@
context "with infinite_precision", :default_infinite_precision_true do
it "uses BigDecimal division" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] },
{ a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] },
{ a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] },
{ a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] },
{ a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] },
]
ts.each do |t|
expect(t[:a].divmod(t[:b])).to eq t[:c]
Expand Down Expand Up @@ -610,10 +610,10 @@
describe "#modulo" do
it "calculates modulo with Integer" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
]
ts.each do |t|
expect(t[:a].modulo(t[:b])).to eq t[:c]
Expand All @@ -622,10 +622,10 @@

it "calculates modulo with Money (same currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) },
]
ts.each do |t|
expect(t[:a].modulo(t[:b])).to eq t[:c]
Expand All @@ -634,10 +634,10 @@

it "calculates modulo with Money (different currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) },
]
ts.each do |t|
expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
Expand All @@ -649,10 +649,10 @@
describe "#%" do
it "calculates modulo with Integer" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
]
ts.each do |t|
expect(t[:a] % t[:b]).to eq t[:c]
Expand All @@ -661,10 +661,10 @@

it "calculates modulo with Money (same currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) },
]
ts.each do |t|
expect(t[:a] % t[:b]).to eq t[:c]
Expand All @@ -673,10 +673,10 @@

it "calculates modulo with Money (different currency)" do
ts = [
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) },
{ a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) },
{ a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) },
]
ts.each do |t|
expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
Expand All @@ -688,10 +688,10 @@
describe "#remainder" do
it "calculates remainder with Integer" do
ts = [
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(1, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(-1, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
{ a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) },
{ a: Money.new(13, :USD), b: -4, c: Money.new(1, :USD) },
{ a: Money.new(-13, :USD), b: 4, c: Money.new(-1, :USD) },
{ a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) },
]
ts.each do |t|
expect(t[:a].remainder(t[:b])).to eq t[:c]
Expand Down
Loading