shopify-money 0.11.4 → 0.11.5

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: 83c2db01e42a2e8495d522c5e2d1e8f1f0503503
4
- data.tar.gz: 57aee0d1d639f9564792794add56654d4adfd8ef
3
+ metadata.gz: 9441b8dab64b7077e0d960f6a81dc069c283ac90
4
+ data.tar.gz: 3fddaf1c805956ee9ca67c9295047698dfeb19f3
5
5
  SHA512:
6
- metadata.gz: e994c9974a9c75e5a3307fb93babbfbff2adaa44606b5eff744586a94ffc5ee4e596894d01fdf03488fc3023090db19fdd5b6e032a33adbe4d9ca3276e795341
7
- data.tar.gz: 0cb26b9374ff0c6dbf583d5415f2c2e2e1390d490b3ce02ac03f86c27ca31cc23aa69e835e66f1149a026b0475aa64164ab7f0787da7e8235f97e1e7a8681494
6
+ metadata.gz: d3c7e5ff1f9ac0a66bbcf0097f5cfdc5c7fa2b202d499850ab5c6620dcece9d96936c3b1e9a8abd6c387be910b8c92d7ef42263755752b4766dcedbac187546e
7
+ data.tar.gz: 36ac7078e3b1960f91d399517c468c29c62744a1068525c23263c4401ab075aae0be8c6e7f166e64050be2a1d6d78dfdcb3f26daab97000a97493a2e3bf41464
@@ -8,7 +8,7 @@ Money.class_eval do
8
8
  def self.deprecate(message)
9
9
  if ACTIVE_SUPPORT_DEFINED
10
10
  external_callstack = caller_locations.reject do |location|
11
- location.to_s.include?('gems/money')
11
+ location.to_s.include?('gems/shopify-money')
12
12
  end
13
13
  active_support_deprecator.warn("[Shopify/Money] #{message}\n", external_callstack)
14
14
  else
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = "0.11.4"
2
+ VERSION = "0.11.5"
3
3
  end
@@ -49,13 +49,13 @@ module MoneyColumn
49
49
  end
50
50
 
51
51
  currency_raw_source = options[:currency] || (send(options[:currency_column]) rescue nil)
52
- currency_source = Money::Helpers.value_to_currency(currency_raw_source)
53
52
 
54
53
  if !money.is_a?(Money)
55
- return self[column] = Money.new(money, currency_source).value
54
+ return self[column] = Money.new(money, currency_raw_source).value
56
55
  end
57
56
 
58
- if currency_raw_source && !currency_source.compatible?(money.currency)
57
+ currency_source = currency_raw_source ? Money::Helpers.value_to_currency(currency_raw_source) : Money::NULL_CURRENCY
58
+ unless currency_source.compatible?(money.currency)
59
59
  Money.deprecate("[money_column] currency mismatch between #{currency_source} and #{money.currency}.")
60
60
  end
61
61
 
@@ -367,4 +367,28 @@ RSpec.describe 'MoneyColumn' do
367
367
  expect(MoneyClassInheritance2.instance_variable_get(:@money_column_options).keys).to_not include('prix')
368
368
  end
369
369
  end
370
+
371
+ describe 'default_currency = nil' do
372
+ around do |example|
373
+ default_currency = Money.default_currency
374
+ Money.default_currency = nil
375
+ example.run
376
+ Money.default_currency = default_currency
377
+ end
378
+
379
+ it 'writes currency from input value to the db' do
380
+ record.update(currency: nil)
381
+ record.update(price: Money.new(7, 'GBP'))
382
+ record.reload
383
+ expect(record.price.value).to eq(7)
384
+ expect(record.price.currency.to_s).to eq('GBP')
385
+ end
386
+
387
+ it 'raises missing currency error when input is not a money object' do
388
+ record.update(currency: nil)
389
+
390
+ expect { record.update(price: 3) }
391
+ .to raise_error(ArgumentError, 'missing currency')
392
+ end
393
+ end
370
394
  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.4
4
+ version: 0.11.5
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-08-22 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler