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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/money/money.rb +12 -3
- data/lib/money/version.rb +1 -1
- data/spec/money_spec.rb +37 -0
- 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: 418b16ca343e15afec56dbfade82d9b8995efc241d4b82d3173c77c81f7ea3fc
|
|
4
|
+
data.tar.gz: 11d4b57794ac31518398361f1fd2c11f39fa5ba6f75baea4c2ed798ddca753c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f7417f5dde55d548afe45cccd10fe16118daf3af28dc83ed543b8ae52149bd88e069f519e63fb5c19aa0734397aef8f264d39ce4f8c4daab7ffcd8005e1b845
|
|
7
|
+
data.tar.gz: 6c3be9a047b8926991416d4b99a53602171d83457f6dac0d53e90ed4cf0e2ee0cb345c4282eae512d40ede474f0c4eaea3ccc02304ec1346211bdbd65e20e3ac
|
data/Gemfile.lock
CHANGED
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
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
|
+
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:
|
|
226
|
+
rubygems_version: 4.0.4
|
|
227
227
|
specification_version: 4
|
|
228
228
|
summary: Shopify's money gem
|
|
229
229
|
test_files: []
|