shopify-money 0.11.1 → 0.11.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
  SHA1:
3
- metadata.gz: 3c62660129723a9f481f8221721c4da317b576a9
4
- data.tar.gz: c70fd044ea5a5a1631c24b3725615fed02cf74b8
3
+ metadata.gz: 2a4ff9c5c0514d928eb29644cca8da3e19123b2f
4
+ data.tar.gz: 99e5abcead9b256bd4fe950c6c84e9af762074f1
5
5
  SHA512:
6
- metadata.gz: 8f8a19b78a2c33b5b0952d433e9d9d88f55fd7105c054478e51656a6137d935a92bf220309116960f08ac56392d3ff0fcf4dafdaafcb7d614874d3e442953bc2
7
- data.tar.gz: 37f28f245c3ba5f4f1833f60981b1c0075f6391f2a88dbdae73ac489b37fdd4dc8c88c12f1ff25292489e58a065f25c29956ee58c7d61d4b5bf3fc85ba02b23c
6
+ metadata.gz: 83ff997ed70b2edd7730b950e7557e813e7c01b1b4b85cd10f5e1957773b0e164811dce6ea20860221763443a9cb0f4399ae973f5664060a4097fe53b1ff5c4b
7
+ data.tar.gz: 58c3dcb9062789668e00758c6cfd78856e7ef3f0b78fe468187a2c605591e6a21c5aaee3589cf86bef7c5a93d458ddd74571d27596392685bc6333503ba63adb
data/lib/money/money.rb CHANGED
@@ -183,7 +183,16 @@ class Money
183
183
  [ReverseOperationProxy.new(other), self]
184
184
  end
185
185
 
186
- def to_money(_currency = nil)
186
+ def to_money(curr = nil)
187
+ if !curr.nil? && no_currency?
188
+ return Money.new(value, curr)
189
+ end
190
+
191
+ curr = Helpers.value_to_currency(curr)
192
+ unless currency.compatible?(curr)
193
+ Money.deprecate("mathematical operation not permitted for Money objects with different currencies #{curr} and #{currency}.")
194
+ end
195
+
187
196
  self
188
197
  end
189
198
 
@@ -388,9 +397,6 @@ class Money
388
397
  raise TypeError, "#{money_or_numeric.class.name} can't be coerced into Money" unless money_or_numeric.respond_to?(:to_money)
389
398
  other = money_or_numeric.to_money(currency)
390
399
 
391
- unless currency.compatible?(other.currency)
392
- Money.deprecate("mathematical operation not permitted for Money objects with different currencies #{other.currency} and #{currency}.")
393
- end
394
400
  yield(other)
395
401
  end
396
402
 
data/lib/money/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
data/spec/money_spec.rb CHANGED
@@ -38,6 +38,15 @@ RSpec.describe "Money" do
38
38
  expect(money.to_money).to eq(money)
39
39
  end
40
40
 
41
+ it "#to_money uses the provided currency when it doesn't already have one" do
42
+ expect(Money.new(1).to_money('CAD')).to eq(Money.new(1, 'CAD'))
43
+ end
44
+
45
+ it "#to_money doesn't overwrite the money object's currency" do
46
+ expect(Money).to receive(:deprecate).once
47
+ expect(Money.new(1, 'USD').to_money('CAD')).to eq(Money.new(1, 'USD'))
48
+ end
49
+
41
50
  it "defaults to 0 when constructed with no arguments" do
42
51
  expect(Money.new).to eq(Money.new(0))
43
52
  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: 0.11.1
4
+ version: 0.11.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: 2018-04-23 00:00:00.000000000 Z
11
+ date: 2018-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler