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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/money/core_extensions.rb +19 -7
- data/lib/money/money.rb +1 -1
- data/lib/money/version.rb +1 -1
- data/spec/core_extensions_spec.rb +8 -0
- data/spec/money_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe8dd7e74692587c2a65622a5ee6f1703ef9c0af100c0b0940f225399f2391f
|
4
|
+
data.tar.gz: e925f921795d0317f06d9d01c88f981560f353a5746e6d293e103a309600f881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b9dccc03de12fd78021c9af07b26fe1897395f7762d0b14d0397064cbffc64eeb96e1e504a91591703c1e1d04c681416fbf51f60fff839939915e600a9bfe9
|
7
|
+
data.tar.gz: 062a4c38ce1fff9b93df7a33d19323e995ebd3a0b74cae3882f8f3f34654febc19bfb761cdb3092838db738868b475ef7fe84002f9c04c8736d49b7484742f85
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
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
@@ -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
|
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.
|
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-
|
11
|
+
date: 2024-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|