shopify-money 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/money.rb +1 -0
- data/lib/money/core_extensions.rb +1 -1
- data/lib/money/errors.rb +7 -0
- data/lib/money/helpers.rb +1 -1
- data/lib/money/money.rb +2 -1
- data/lib/money/money_parser.rb +7 -3
- data/lib/money/version.rb +1 -1
- data/spec/core_extensions_spec.rb +17 -0
- data/spec/money_column_spec.rb +18 -1
- data/spec/money_parser_spec.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c2db01e42a2e8495d522c5e2d1e8f1f0503503
|
4
|
+
data.tar.gz: 57aee0d1d639f9564792794add56654d4adfd8ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e994c9974a9c75e5a3307fb93babbfbff2adaa44606b5eff744586a94ffc5ee4e596894d01fdf03488fc3023090db19fdd5b6e032a33adbe4d9ca3276e795341
|
7
|
+
data.tar.gz: 0cb26b9374ff0c6dbf583d5415f2c2e2e1390d490b3ce02ac03f86c27ca31cc23aa69e835e66f1149a026b0475aa64164ab7f0787da7e8235f97e1e7a8681494
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/Shopify/money.svg?branch=master)](https://travis-ci.org/Shopify/money) [![codecov](https://codecov.io/gh/Shopify/money/branch/master/graph/badge.svg)](https://codecov.io/gh/Shopify/money)
|
4
4
|
|
5
5
|
|
6
|
-
money_column expects a
|
6
|
+
money_column expects a DECIMAL(21,3) database field.
|
7
7
|
|
8
8
|
### Features
|
9
9
|
|
data/lib/money.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative 'money/helpers'
|
|
3
3
|
require_relative 'money/currency'
|
4
4
|
require_relative 'money/null_currency'
|
5
5
|
require_relative 'money/money'
|
6
|
+
require_relative 'money/errors'
|
6
7
|
require_relative 'money/deprecations'
|
7
8
|
require_relative 'money/accounting_money_parser'
|
8
9
|
require_relative 'money/core_extensions'
|
data/lib/money/errors.rb
ADDED
data/lib/money/helpers.rb
CHANGED
data/lib/money/money.rb
CHANGED
@@ -190,7 +190,8 @@ class Money
|
|
190
190
|
|
191
191
|
curr = Helpers.value_to_currency(curr)
|
192
192
|
unless currency.compatible?(curr)
|
193
|
-
Money.deprecate("mathematical operation not permitted for Money objects with different currencies #{curr} and #{currency}."
|
193
|
+
Money.deprecate("mathematical operation not permitted for Money objects with different currencies #{curr} and #{currency}. " \
|
194
|
+
"A Money::IncompatibleCurrencyError will raise in the next major release")
|
194
195
|
end
|
195
196
|
|
196
197
|
self
|
data/lib/money/money_parser.rb
CHANGED
@@ -63,14 +63,18 @@ class MoneyParser
|
|
63
63
|
|
64
64
|
def parse(input, currency = nil, strict: false)
|
65
65
|
currency = Money::Helpers.value_to_currency(currency)
|
66
|
-
amount =
|
66
|
+
amount = extract_amount_from_string(input, currency, strict)
|
67
67
|
Money.new(amount, currency)
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
|
-
def
|
73
|
-
|
72
|
+
def extract_amount_from_string(input, currency, strict)
|
73
|
+
unless input.is_a?(String)
|
74
|
+
return input
|
75
|
+
end
|
76
|
+
|
77
|
+
if input.strip.empty?
|
74
78
|
return '0'
|
75
79
|
end
|
76
80
|
|
data/lib/money/version.rb
CHANGED
@@ -14,6 +14,10 @@ RSpec.describe Integer do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it_should_behave_like "an object supporting to_money"
|
17
|
+
|
18
|
+
it "parses 0 to Money.zero" do
|
19
|
+
expect(0.to_money).to eq(Money.zero)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
RSpec.describe Float do
|
@@ -23,6 +27,10 @@ RSpec.describe Float do
|
|
23
27
|
end
|
24
28
|
|
25
29
|
it_should_behave_like "an object supporting to_money"
|
30
|
+
|
31
|
+
it "parses 0.0 to Money.zero" do
|
32
|
+
expect(0.0.to_money).to eq(Money.zero)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
RSpec.describe String do
|
@@ -32,6 +40,11 @@ RSpec.describe String do
|
|
32
40
|
end
|
33
41
|
|
34
42
|
it_should_behave_like "an object supporting to_money"
|
43
|
+
|
44
|
+
it "parses an empty string to Money.zero" do
|
45
|
+
expect(''.to_money).to eq(Money.zero)
|
46
|
+
expect(' '.to_money).to eq(Money.zero)
|
47
|
+
end
|
35
48
|
end
|
36
49
|
|
37
50
|
RSpec.describe BigDecimal do
|
@@ -41,4 +54,8 @@ RSpec.describe BigDecimal do
|
|
41
54
|
end
|
42
55
|
|
43
56
|
it_should_behave_like "an object supporting to_money"
|
57
|
+
|
58
|
+
it "parses a zero BigDecimal to Money.zero" do
|
59
|
+
expect(BigDecimal.new("-0.000").to_money).to eq(Money.zero)
|
60
|
+
end
|
44
61
|
end
|
data/spec/money_column_spec.rb
CHANGED
@@ -291,7 +291,7 @@ RSpec.describe 'MoneyColumn' do
|
|
291
291
|
expect(record.instance_variable_get(:@money_column_cache)["price"]).to eq(price)
|
292
292
|
end
|
293
293
|
|
294
|
-
it 'reload will clear
|
294
|
+
it 'reload will clear memoized money values' do
|
295
295
|
price = Money.new(1, 'USD')
|
296
296
|
record = MoneyRecord.create(price: price)
|
297
297
|
expect(record.price).to eq(price)
|
@@ -301,6 +301,23 @@ RSpec.describe 'MoneyColumn' do
|
|
301
301
|
record.price
|
302
302
|
expect(record.instance_variable_get(:@money_column_cache)["price"]).to eq(price)
|
303
303
|
end
|
304
|
+
|
305
|
+
it 'reload will clear record cache' do
|
306
|
+
price = Money.new(1, 'USD')
|
307
|
+
price2 = Money.new(2, 'USD')
|
308
|
+
|
309
|
+
record = MoneyRecord.create(price: price)
|
310
|
+
expect(record.price).to eq(price)
|
311
|
+
expect(record[:price]).to eq(price)
|
312
|
+
|
313
|
+
ActiveRecord::Base.connection.execute("UPDATE money_records SET price=#{price2.value} WHERE id=#{record.id}")
|
314
|
+
expect(record[:price]).to_not eq(price2)
|
315
|
+
expect(record.price).to_not eq(price2)
|
316
|
+
|
317
|
+
record.reload
|
318
|
+
expect(record[:price]).to eq(price2)
|
319
|
+
expect(record.price).to eq(price2)
|
320
|
+
end
|
304
321
|
end
|
305
322
|
|
306
323
|
describe 'ActiveRecord querying' do
|
data/spec/money_parser_spec.rb
CHANGED
@@ -333,6 +333,10 @@ RSpec.describe MoneyParser do
|
|
333
333
|
it "parses 1.32" do
|
334
334
|
expect(@parser.parse(1.32)).to eq(Money.new(1.32))
|
335
335
|
end
|
336
|
+
|
337
|
+
it "parses 1.234" do
|
338
|
+
expect(@parser.parse(1.234)).to eq(Money.new(1.234))
|
339
|
+
end
|
336
340
|
end
|
337
341
|
|
338
342
|
describe "parsing with thousands separators" do
|
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
|
+
version: 0.11.4
|
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-
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/money/currency.rb
|
135
135
|
- lib/money/currency/loader.rb
|
136
136
|
- lib/money/deprecations.rb
|
137
|
+
- lib/money/errors.rb
|
137
138
|
- lib/money/helpers.rb
|
138
139
|
- lib/money/money.rb
|
139
140
|
- lib/money/money_parser.rb
|