shopify-money 3.2.5 → 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: da7880db33de1bba4ca71e5fa179fd09c200419af6d8ff9f44ca8fcd610fda11
4
- data.tar.gz: 8e423388158e2c3e8a26b51b15ad4aef414d391550736fa1f03da3e1d1eb8bfb
3
+ metadata.gz: 418b16ca343e15afec56dbfade82d9b8995efc241d4b82d3173c77c81f7ea3fc
4
+ data.tar.gz: 11d4b57794ac31518398361f1fd2c11f39fa5ba6f75baea4c2ed798ddca753c5
5
5
  SHA512:
6
- metadata.gz: a6e74800a95e3d5ab5d79551a1ffae9e45ef72ad82b229c070bb7d909f4d522f1fe4c191eb570b03c21676909c965beb31d90f63658300b522cf5c991827dbd8
7
- data.tar.gz: 39c15b0575f1343526d509506ee510ecc1f76f6dea463db446de01ab902455dbb91bedc28a07a368950329d04711d1a5ac470ce1926bf1889dbf410f0ab24fde
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.5)
4
+ shopify-money (3.2.6)
5
5
  bigdecimal (>= 3.0)
6
6
 
7
7
  GEM
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
 
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.5"
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.5
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.7.1
226
+ rubygems_version: 4.0.4
227
227
  specification_version: 4
228
228
  summary: Shopify's money gem
229
229
  test_files: []