shopify-money 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75140fb176288187177a79f673b9741b69a4ae96e02b314139318d7ff817b8b9
4
- data.tar.gz: d98030d40029dbb686b83b090ab11e43628a194bd2902ba130f5161e860dc839
3
+ metadata.gz: afe8dd7e74692587c2a65622a5ee6f1703ef9c0af100c0b0940f225399f2391f
4
+ data.tar.gz: e925f921795d0317f06d9d01c88f981560f353a5746e6d293e103a309600f881
5
5
  SHA512:
6
- metadata.gz: 3e140de24fea5b7c90b5044f4b9732e013187a6cad34c7ea6bd9d8119cd118907c7faeb934ed533085389e3e55f7ba0649697e7563ec87380c6fc62ff9a1c935
7
- data.tar.gz: 5a1d77f26c7886fc1a96edee8a920df4262385fce001209d640c9427e986e9d95d2d9a8232fca17a670758f45a7bc219d728386c080606d1f8bc348cb71ba0a3
6
+ metadata.gz: 99b9dccc03de12fd78021c9af07b26fe1897395f7762d0b14d0397064cbffc64eeb96e1e504a91591703c1e1d04c681416fbf51f60fff839939915e600a9bfe9
7
+ data.tar.gz: 062a4c38ce1fff9b93df7a33d19323e995ebd3a0b74cae3882f8f3f34654febc19bfb761cdb3092838db738868b475ef7fe84002f9c04c8736d49b7484742f85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopify-money (2.2.1)
4
+ shopify-money (2.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -14,14 +14,26 @@ end
14
14
  # '100.37'.to_money => #<Money @cents=10037>
15
15
  class String
16
16
  def to_money(currency = nil)
17
- if Money.config.legacy_deprecations
18
- Money::Parser::Fuzzy.parse(self, currency).tap do |money|
19
- message = "`#{self}.to_money` will behave like `Money.new` and raise on the next release. " \
20
- "To parse user input, do so on the browser and use the user's locale."
21
- Money.deprecate(message) if money.value != BigDecimal(self, exception: false)
17
+ currency = Money::Helpers.value_to_currency(currency)
18
+
19
+ unless Money.config.legacy_deprecations
20
+ return Money.new(self, currency)
21
+ end
22
+
23
+ Money::Parser::Fuzzy.parse(self, currency).tap do |money|
24
+ new_value = BigDecimal(self, exception: false)&.round(currency.minor_units)
25
+ old_value = money.value
26
+
27
+ if new_value != old_value
28
+ message = "`\"#{self}\".to_money` will soon behave like `Money.new(\"#{self}\")` and "
29
+ message +=
30
+ if new_value.nil?
31
+ "raise an ArgumentError exception. Use the browser's locale to parse money strings."
32
+ else
33
+ "return #{new_value} instead of #{old_value}."
34
+ end
35
+ Money.deprecate(message)
22
36
  end
23
- else
24
- Money.new(self, currency)
25
37
  end
26
38
  end
27
39
  end
data/lib/money/money.rb CHANGED
@@ -116,7 +116,7 @@ class Money
116
116
  return amount
117
117
  end
118
118
 
119
- msg = "Money.new is attempting to change currency of an existing money object"
119
+ msg = "Money.new(Money.new(amount, #{amount.currency}), #{currency}) is changing the currency of an existing money object"
120
120
  if Money.config.legacy_deprecations
121
121
  Money.deprecate("#{msg}. A Money::IncompatibleCurrencyError will raise in the next major release")
122
122
  return Money.new(amount.value, currency)
data/lib/money/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Money
3
- VERSION = "2.2.1"
3
+ VERSION = "2.2.2"
4
4
  end
@@ -61,6 +61,14 @@ RSpec.describe String do
61
61
  end
62
62
  end
63
63
 
64
+ it "#to_money does not warn when it already behaves like Money.new" do
65
+ configure(legacy_deprecations: true) do
66
+ expect(Money).to receive(:deprecate).never
67
+ expect("71.94999999999999".to_money("USD")).to eq(Money.new("71.95", "USD"))
68
+ expect("0.001".to_money("USD")).to eq(Money.new("0", "USD"))
69
+ end
70
+ end
71
+
64
72
  it "#to_money should behave like Money.new with three decimal places amounts" do
65
73
  expect("29.000".to_money("USD")).to eq(Money.new("29.00", "USD"))
66
74
  end
data/spec/money_spec.rb CHANGED
@@ -99,7 +99,7 @@ RSpec.describe "Money" do
99
99
 
100
100
  it "legacy_deprecations constructor with money used the constructor currency" do
101
101
  configure(legacy_deprecations: true) do
102
- expect(Money).to receive(:deprecate).with(match(/Money.new is attempting to change currency of an existing money object/)).once
102
+ expect(Money).to receive(:deprecate).with(match(/Money.new\(Money.new\(amount, USD\), CAD\) is changing the currency of an existing money object/)).once
103
103
  expect(Money.new(Money.new(1, 'USD'), 'CAD')).to eq(Money.new(1, 'CAD'))
104
104
  end
105
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-25 00:00:00.000000000 Z
11
+ date: 2024-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler