diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03306a7d01..6ae1324b27 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,54 +6,11 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/FirstArrayElementIndentation: - Exclude: - - 'spec/money/allocation_spec.rb' - - 'spec/money/arithmetic_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'spec/currency_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -Layout/HeredocIndentation: - Exclude: - - 'spec/money_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Width, AllowedPatterns. -Layout/IndentationWidth: - Exclude: - - 'spec/money_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented -Layout/LineEndStringConcatenationIndentation: - Exclude: - - 'lib/money/bank/variable_exchange.rb' - - 'lib/money/money/arithmetic.rb' - # This cop supports safe autocorrection (--autocorrect). Layout/MultilineBlockLayout: Exclude: - 'spec/money_spec.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'lib/money/money.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: diff --git a/lib/money/bank/variable_exchange.rb b/lib/money/bank/variable_exchange.rb index 6b10d36e1a..ea96d46a16 100644 --- a/lib/money/bank/variable_exchange.rb +++ b/lib/money/bank/variable_exchange.rb @@ -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 diff --git a/lib/money/money.rb b/lib/money/money.rb index bc3f156c6e..c41d8e6040 100644 --- a/lib/money/money.rb +++ b/lib/money/money.rb @@ -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 diff --git a/lib/money/money/arithmetic.rb b/lib/money/money/arithmetic.rb index 3e72e83496..ee722b04cc 100644 --- a/lib/money/money/arithmetic.rb +++ b/lib/money/money/arithmetic.rb @@ -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 diff --git a/spec/currency_spec.rb b/spec/currency_spec.rb index a87386da55..3e223380ee 100644 --- a/spec/currency_spec.rb +++ b/spec/currency_spec.rb @@ -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: " ", ) @@ -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, ) @@ -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 diff --git a/spec/money/allocation_spec.rb b/spec/money/allocation_spec.rb index ff8beab2c3..4d80bd9deb 100644 --- a/spec/money/allocation_spec.rb +++ b/spec/money/allocation_spec.rb @@ -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 @@ -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 diff --git a/spec/money/arithmetic_spec.rb b/spec/money/arithmetic_spec.rb index 76283ebc92..eac6cdb1be 100644 --- a/spec/money/arithmetic_spec.rb +++ b/spec/money/arithmetic_spec.rb @@ -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] @@ -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] @@ -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)) @@ -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] @@ -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] @@ -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)) @@ -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] @@ -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] @@ -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] @@ -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)) @@ -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] @@ -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] @@ -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)) @@ -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] diff --git a/spec/money_spec.rb b/spec/money_spec.rb index 66f8f5e482..8d76c47eb4 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -397,26 +397,27 @@ end context "loading a serialized Money via YAML" do - let(:serialized) { <