shopify-money 3.2.4 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22d6b7f34e2df9d08722a1b5a3c4297bb95d68557b7e82c448476478336cf339
4
- data.tar.gz: c267cac812901641a799ddc08afd446051f808c632d75ef62c8c80ad4237bf72
3
+ metadata.gz: 418b16ca343e15afec56dbfade82d9b8995efc241d4b82d3173c77c81f7ea3fc
4
+ data.tar.gz: 11d4b57794ac31518398361f1fd2c11f39fa5ba6f75baea4c2ed798ddca753c5
5
5
  SHA512:
6
- metadata.gz: 4da3c3318564210997ae4e3a56c99e46d4702de1c19d258f61948f7aee0b978c7ccaea8f9be13d270216af9ad23d52d25e48a44e514e154014bd179ca217403f
7
- data.tar.gz: e1378b9689d6e7a22cf4d9892a4802e09ecdca0e67b4bb3bc5a5c7c924fa06c3fdf0bea6ab5b4f65db206cd06c4becd5f23b0f46381ad425350aa4925d4b9e8b
6
+ metadata.gz: 1f7417f5dde55d548afe45cccd10fe16118daf3af28dc83ed543b8ae52149bd88e069f519e63fb5c19aa0734397aef8f264d39ce4f8c4daab7ffcd8005e1b845
7
+ data.tar.gz: 6c3be9a047b8926991416d4b99a53602171d83457f6dac0d53e90ed4cf0e2ee0cb345c4282eae512d40ede474f0c4eaea3ccc02304ec1346211bdbd65e20e3ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopify-money (3.2.4)
4
+ shopify-money (3.2.6)
5
5
  bigdecimal (>= 3.0)
6
6
 
7
7
  GEM
@@ -108,7 +108,7 @@ GEM
108
108
  pp (>= 0.6.0)
109
109
  rdoc (>= 4.0.0)
110
110
  reline (>= 0.4.2)
111
- json (2.12.2)
111
+ json (2.13.2)
112
112
  language_server-protocol (3.17.0.5)
113
113
  lint_roller (1.1.0)
114
114
  logger (1.7.0)
@@ -125,7 +125,7 @@ GEM
125
125
  mini_mime (1.1.5)
126
126
  mini_portile2 (2.8.8)
127
127
  minitest (5.25.5)
128
- net-imap (0.5.6)
128
+ net-imap (0.5.7)
129
129
  date
130
130
  net-protocol
131
131
  net-pop (0.1.2)
@@ -135,22 +135,22 @@ GEM
135
135
  net-smtp (0.5.1)
136
136
  net-protocol
137
137
  nio4r (2.7.4)
138
- nokogiri (1.18.7)
138
+ nokogiri (1.18.8)
139
139
  mini_portile2 (~> 2.8.2)
140
140
  racc (~> 1.4)
141
- nokogiri (1.18.7-aarch64-linux-gnu)
141
+ nokogiri (1.18.8-aarch64-linux-gnu)
142
142
  racc (~> 1.4)
143
- nokogiri (1.18.7-arm-linux-gnu)
143
+ nokogiri (1.18.8-arm-linux-gnu)
144
144
  racc (~> 1.4)
145
- nokogiri (1.18.7-arm64-darwin)
145
+ nokogiri (1.18.8-arm64-darwin)
146
146
  racc (~> 1.4)
147
- nokogiri (1.18.7-x86_64-darwin)
147
+ nokogiri (1.18.8-x86_64-darwin)
148
148
  racc (~> 1.4)
149
- nokogiri (1.18.7-x86_64-linux-gnu)
149
+ nokogiri (1.18.8-x86_64-linux-gnu)
150
150
  racc (~> 1.4)
151
151
  ostruct (0.6.1)
152
152
  parallel (1.27.0)
153
- parser (3.3.8.0)
153
+ parser (3.3.9.0)
154
154
  ast (~> 2.4.1)
155
155
  racc
156
156
  pp (0.6.2)
@@ -167,8 +167,8 @@ GEM
167
167
  date
168
168
  stringio
169
169
  racc (1.8.1)
170
- rack (3.1.12)
171
- rack-session (2.1.0)
170
+ rack (3.1.14)
171
+ rack-session (2.1.1)
172
172
  base64 (>= 0.1.0)
173
173
  rack (>= 3.0.0)
174
174
  rack-test (2.2.0)
@@ -208,7 +208,7 @@ GEM
208
208
  rake (13.2.1)
209
209
  rdoc (6.13.1)
210
210
  psych (>= 4.0.0)
211
- regexp_parser (2.10.0)
211
+ regexp_parser (2.11.0)
212
212
  reline (0.6.1)
213
213
  io-console (~> 0.5)
214
214
  rspec (3.13.0)
@@ -224,7 +224,7 @@ GEM
224
224
  diff-lcs (>= 1.2.0, < 2.0)
225
225
  rspec-support (~> 3.13.0)
226
226
  rspec-support (3.13.1)
227
- rubocop (1.75.7)
227
+ rubocop (1.79.1)
228
228
  json (~> 2.3)
229
229
  language_server-protocol (~> 3.17.0.2)
230
230
  lint_roller (~> 1.1.0)
@@ -232,10 +232,10 @@ GEM
232
232
  parser (>= 3.3.0.2)
233
233
  rainbow (>= 2.2.2, < 4.0)
234
234
  regexp_parser (>= 2.9.3, < 3.0)
235
- rubocop-ast (>= 1.44.0, < 2.0)
235
+ rubocop-ast (>= 1.46.0, < 2.0)
236
236
  ruby-progressbar (~> 1.7)
237
237
  unicode-display_width (>= 2.4.0, < 4.0)
238
- rubocop-ast (1.44.1)
238
+ rubocop-ast (1.46.0)
239
239
  parser (>= 3.3.7.2)
240
240
  prism (~> 1.4)
241
241
  rubocop-performance (1.25.0)
data/lib/money/money.rb CHANGED
@@ -135,6 +135,10 @@ class Money
135
135
 
136
136
  def initialize(value, currency)
137
137
  raise ArgumentError if value.nan?
138
+ if value.infinite?
139
+ Money.deprecate("Initializing Money with infinity is deprecated and will raise an ArgumentError in v4")
140
+ end
141
+
138
142
  @currency = Helpers.value_to_currency(currency)
139
143
  @value = BigDecimal(value.round(@currency.minor_units))
140
144
  freeze
@@ -162,9 +166,14 @@ class Money
162
166
  end
163
167
 
164
168
  def <=>(other)
165
- return unless other.respond_to?(:to_money)
166
- arithmetic(other) do |money|
167
- value <=> money.value
169
+ if other.is_a?(Numeric)
170
+ return value <=> other
171
+ end
172
+
173
+ if other.respond_to?(:to_money)
174
+ arithmetic(other) do |money|
175
+ value <=> money.value
176
+ end
168
177
  end
169
178
  end
170
179
 
@@ -11,8 +11,6 @@ class Money
11
11
  Money.new(hash["value"], hash["currency"])
12
12
  end
13
13
 
14
- private
15
-
16
14
  def klass
17
15
  Money
18
16
  end
data/lib/money/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Money
4
- VERSION = "3.2.4"
4
+ VERSION = "3.2.6"
5
5
  end
data/spec/money_spec.rb CHANGED
@@ -493,6 +493,16 @@ RSpec.describe "Money" do
493
493
  expect { Money.new( 0.0 / 0) }.to raise_error(ArgumentError)
494
494
  end
495
495
 
496
+ it "raises when constructed with positive infinity" do
497
+ expect(Money).to receive(:deprecate).once
498
+ Money.new(Float::INFINITY)
499
+ end
500
+
501
+ it "raises when constructed with negative infinity" do
502
+ expect(Money).to receive(:deprecate).once
503
+ Money.new(-Float::INFINITY)
504
+ end
505
+
496
506
  it "is comparable with non-money objects" do
497
507
  expect(money).not_to eq(nil)
498
508
  end
@@ -585,6 +595,7 @@ RSpec.describe "Money" do
585
595
  let (:nil_10) { Money.new(10.00, Money::NULL_CURRENCY) }
586
596
  let (:nil_20) { Money.new(20.00, Money::NULL_CURRENCY) }
587
597
  let (:usd_10) { Money.new(10.00, 'USD') }
598
+ let (:jpy_10) { Money.new(10, 'JPY') }
588
599
 
589
600
  it "<=> can compare with and without currency" do
590
601
  expect(Money.new(1000, Money::NULL_CURRENCY) <=> Money.new(2000, 'JPY')).to eq(-1)
@@ -746,6 +757,32 @@ RSpec.describe "Money" do
746
757
  it { expect { cad_10 <= nil }.to(raise_error(ArgumentError)) }
747
758
  it { expect { cad_10 < nil }.to(raise_error(ArgumentError)) }
748
759
  end
760
+
761
+ describe('infinity comparisons') do
762
+ it { expect(cad_10 <=> Float::INFINITY).to(eq(-1)) }
763
+ it { expect(cad_10 < Float::INFINITY).to(eq(true)) }
764
+ it { expect(cad_10 <= Float::INFINITY).to(eq(true)) }
765
+ it { expect(cad_10 > Float::INFINITY).to(eq(false)) }
766
+ it { expect(cad_10 >= Float::INFINITY).to(eq(false)) }
767
+
768
+ it { expect(cad_10 <=> -Float::INFINITY).to(eq(1)) }
769
+ it { expect(cad_10 > -Float::INFINITY).to(eq(true)) }
770
+ it { expect(cad_10 >= -Float::INFINITY).to(eq(true)) }
771
+ it { expect(cad_10 < -Float::INFINITY).to(eq(false)) }
772
+ it { expect(cad_10 <= -Float::INFINITY).to(eq(false)) }
773
+
774
+ it { expect(jpy_10 <=> Float::INFINITY).to(eq(-1)) }
775
+ it { expect(jpy_10 < Float::INFINITY).to(eq(true)) }
776
+ it { expect(jpy_10 <= Float::INFINITY).to(eq(true)) }
777
+ it { expect(jpy_10 > Float::INFINITY).to(eq(false)) }
778
+ it { expect(jpy_10 >= Float::INFINITY).to(eq(false)) }
779
+
780
+ it { expect(jpy_10 <=> -Float::INFINITY).to(eq(1)) }
781
+ it { expect(jpy_10 > -Float::INFINITY).to(eq(true)) }
782
+ it { expect(jpy_10 >= -Float::INFINITY).to(eq(true)) }
783
+ it { expect(jpy_10 < -Float::INFINITY).to(eq(false)) }
784
+ it { expect(jpy_10 <= -Float::INFINITY).to(eq(false)) }
785
+ end
749
786
  end
750
787
 
751
788
  describe "#subunits" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  requirements: []
226
- rubygems_version: 3.6.9
226
+ rubygems_version: 4.0.4
227
227
  specification_version: 4
228
228
  summary: Shopify's money gem
229
229
  test_files: []