diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 39988b994d..2b237d75af 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -74,4 +74,4 @@ Style/IfInsideElse: # Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. # URISchemes: http, https Layout/LineLength: - Max: 433 + Max: 200 diff --git a/lib/money/currency.rb b/lib/money/currency.rb index 1da7a79016..1b630fe37a 100644 --- a/lib/money/currency.rb +++ b/lib/money/currency.rb @@ -354,7 +354,22 @@ def hash # @example # Money::Currency.new(:usd) #=> # def inspect - "#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, exponent: #{exponent}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}, smallest_denomination: #{smallest_denomination}, format: #{format}>" + "#<#{self.class.name} " \ + "id: #{id}, " \ + "priority: #{priority}, " \ + "symbol_first: #{symbol_first}, " \ + "thousands_separator: #{thousands_separator}, " \ + "html_entity: #{html_entity}, " \ + "decimal_mark: #{decimal_mark}, " \ + "name: #{name}, " \ + "symbol: #{symbol}, " \ + "subunit_to_unit: #{subunit_to_unit}, " \ + "exponent: #{exponent}, " \ + "iso_code: #{iso_code}, " \ + "iso_numeric: #{iso_numeric}, " \ + "subunit: #{subunit}, " \ + "smallest_denomination: #{smallest_denomination}, " \ + "format: #{format}>" end # Returns a string representation corresponding to the upcase +id+ diff --git a/lib/money/money/formatter.rb b/lib/money/money/formatter.rb index d457ec817c..36555448d5 100644 --- a/lib/money/money/formatter.rb +++ b/lib/money/money/formatter.rb @@ -117,7 +117,11 @@ class Formatter # # @example # Money.ca_dollar(570).format(html_wrap: true, with_currency: true) - # #=> "$5.70 CAD" + # #=> "$" \ + # "5" \ + # "." \ + # "70 " \ + # "CAD" # # @option rules [Boolean] :sign_before_symbol (false) Whether the sign should be # before the currency symbol. diff --git a/spec/currency_spec.rb b/spec/currency_spec.rb index 186de1be30..04da83328d 100644 --- a/spec/currency_spec.rb +++ b/spec/currency_spec.rb @@ -392,8 +392,41 @@ def to_s describe "#inspect" do it "works as documented" do - expect(described_class.new(:usd).inspect).to eq "#" - expect(described_class.new(:aed).inspect).to eq "#" + expect(described_class.new(:usd).inspect).to eq( + "#", + ) + expect(described_class.new(:aed).inspect).to eq( + "#", + ) end end diff --git a/spec/money/allocation_spec.rb b/spec/money/allocation_spec.rb index 83eca415e7..eda4ca54c6 100644 --- a/spec/money/allocation_spec.rb +++ b/spec/money/allocation_spec.rb @@ -140,20 +140,76 @@ context "with an allocation seen in the wild" do it "allocates the full amount" do amount = 700273 - allocations = [1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.170126087450276, 1.0, 1.0, 1.0, 1.0] + allocations = [ + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.170126087450276, + 1.0, + 1.0, + 1.0, + 1.0, + ] result = described_class.generate(amount, allocations) expect(result.reduce(&:+)).to eq(amount) - expect(result).to eq([61566, 61565, 61565, 61565, 61565, 61565, 61565, 60953, 52091, 52091, 52091, 52091]) + expect(result).to eq( + [ + 61566, + 61565, + 61565, + 61565, + 61565, + 61565, + 61565, + 60953, + 52091, + 52091, + 52091, + 52091, + ], + ) end it "allocates the full -amount" do amount = -700273 - allocations = [1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.170126087450276, 1.0, 1.0, 1.0, 1.0] + allocations = [ + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.1818583143661, + 1.170126087450276, + 1.0, + 1.0, + 1.0, + 1.0, + ] result = described_class.generate(amount, allocations) expect(result.reduce(&:+)).to eq(amount) - expect(result).to eq([-61566, -61565, -61565, -61565, -61565, -61565, -61565, -60953, -52091, -52091, -52091, -52091]) + expect(result).to eq( + [ + -61566, + -61565, + -61565, + -61565, + -61565, + -61565, + -61565, + -60953, + -52091, + -52091, + -52091, + -52091, + ], + ) end context "when specified precision" do diff --git a/spec/money/formatting_spec.rb b/spec/money/formatting_spec.rb index 289515bb57..4271b5b26a 100644 --- a/spec/money/formatting_spec.rb +++ b/spec/money/formatting_spec.rb @@ -417,14 +417,19 @@ end specify "(south_asian_number_formatting: true) works as documented" do - expect(Money.new(10000000, "INR").format(south_asian_number_formatting: true, symbol: false)).to eq "1,00,000.00" - expect(Money.new(1000000000, "INDIAN_BAR").format(south_asian_number_formatting: true, symbol: false)).to eq "1,00,000.0000" - expect(Money.new(10000000).format(south_asian_number_formatting: true)).to eq "$1,00,000.00" + expect(Money.new(10000000, "INR").format(south_asian_number_formatting: true, symbol: false)) + .to eq "1,00,000.00" + expect(Money.new(1000000000, "INDIAN_BAR").format(south_asian_number_formatting: true, symbol: false)) + .to eq "1,00,000.0000" + expect(Money.new(10000000).format(south_asian_number_formatting: true)) + .to eq "$1,00,000.00" end specify "(south_asian_number_formatting: true and no_cents_if_whole => true) works as documented" do - expect(Money.new(10000000, "INR").format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)).to eq "1,00,000" - expect(Money.new(1000000000, "INDIAN_BAR").format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)).to eq "1,00,000" + expect(Money.new(10000000, "INR").format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)) + .to eq "1,00,000" + expect(Money.new(1000000000, "INDIAN_BAR").format(south_asian_number_formatting: true, symbol: false, no_cents_if_whole: true)) + .to eq "1,00,000" end end @@ -488,7 +493,13 @@ specify "(html_wrap: true, with_currency: true)" do string = Money.ca_dollar(570).format(html_wrap: true, with_currency: true) - expect(string).to eq "$5.70 CAD" + expect(string).to eq( + "$" \ + "5" \ + "." \ + "70 " \ + "CAD", + ) end specify "should fallback to symbol if entity is not available" do