shopify-money 1.2.1 → 1.3.0
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/README.md +8 -11
- data/lib/money/core_extensions.rb +9 -1
- data/lib/money/deprecations.rb +4 -1
- data/lib/money/version.rb +1 -1
- data/lib/rubocop/cop/money/missing_currency.rb +2 -1
- data/lib/rubocop/cop/money/unsafe_to_money.rb +1 -1
- data/spec/core_extensions_spec.rb +20 -2
- data/spec/deprecations_spec.rb +9 -0
- data/spec/rubocop/cop/money/missing_currency_spec.rb +7 -0
- data/spec/rubocop/cop/money/unsafe_to_money_spec.rb +6 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 968f61cd2788112e0310dad876e0100eef9bdc375b39d10b7a34e98cb23650fc
|
4
|
+
data.tar.gz: 279e00665cf1561add517a797afc0d732410813233da3dfe6c09225de9108445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5abf64ebc32b62bbb31906b977a05e66362dc68453c454efedfe0c83ae5743454c526882fbec437f4874d36ae5d384947c64175a8d50fba0fb339c58d77500c5
|
7
|
+
data.tar.gz: 76a439a0dca761dc12b3fd44e90737aee88fe26f11ed20af1ab9eba45ce20d6fa55265c9130ee034548d5b799621eef4d328808ca12fcfdcca6b02e258a496b4
|
data/README.md
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
# money
|
2
2
|
|
3
|
-
[](https://github.com/Shopify/money/actions?query=workflow%3Atests+branch%
|
3
|
+
[](https://github.com/Shopify/money/actions?query=workflow%3Atests+branch%3Amain)
|
4
4
|
|
5
5
|
|
6
6
|
money_column expects a DECIMAL(21,3) database field.
|
7
7
|
|
8
8
|
### Features
|
9
9
|
|
10
|
-
-
|
11
|
-
- Provides a `Money` class which encapsulates all information about
|
12
|
-
|
13
|
-
-
|
14
|
-
|
15
|
-
- Does NOT provides APIs for exchanging money from one currency to another.
|
16
|
-
- wont lose pennies during division!
|
17
|
-
- Money::NullCurrency for no currency support
|
10
|
+
- Provides a `Money` class which encapsulates all information about a certain amount of money, such as its value and its currency.
|
11
|
+
- Provides a `Money::Currency` class which encapsulates all information about a monetary unit.
|
12
|
+
- Represents monetary values as decimals. No need to convert your amounts every time you use them. Easily understand the data in your DB.
|
13
|
+
- Does NOT provide APIs for exchanging money from one currency to another.
|
14
|
+
- Will not lose pennies during divisions
|
18
15
|
|
19
16
|
## Installation
|
20
17
|
|
@@ -22,7 +19,7 @@ money_column expects a DECIMAL(21,3) database field.
|
|
22
19
|
|
23
20
|
## Upgrading to v1.0
|
24
21
|
|
25
|
-
see instructions and breaking changes: https://github.com/Shopify/money/blob/
|
22
|
+
see instructions and breaking changes: https://github.com/Shopify/money/blob/main/UPGRADING.md
|
26
23
|
|
27
24
|
## Usage
|
28
25
|
|
@@ -171,7 +168,7 @@ Money/UnsafeToMoney:
|
|
171
168
|
|
172
169
|
## Contributing to money
|
173
170
|
|
174
|
-
- Check out the latest
|
171
|
+
- Check out the latest main to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
175
172
|
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
176
173
|
- Fork the project
|
177
174
|
- Start a feature/bugfix branch
|
@@ -14,6 +14,14 @@ end
|
|
14
14
|
# '100.37'.to_money => #<Money @cents=10037>
|
15
15
|
class String
|
16
16
|
def to_money(currency = nil)
|
17
|
-
Money
|
17
|
+
if Money.config.legacy_deprecations
|
18
|
+
Money::Parser::Fuzzy.parse(self, currency).tap do |money|
|
19
|
+
message = "`#{self}.to_money` will behave like `Money.new` and raise on the next release. " \
|
20
|
+
"To parse user input, do so on the browser and use the user's locale."
|
21
|
+
Money.deprecate(message) if money.value != BigDecimal(self, exception: false)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
Money.new(self, currency)
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
data/lib/money/deprecations.rb
CHANGED
@@ -3,7 +3,10 @@ Money.class_eval do
|
|
3
3
|
ACTIVE_SUPPORT_DEFINED = defined?(ActiveSupport)
|
4
4
|
|
5
5
|
def self.active_support_deprecator
|
6
|
-
@active_support_deprecator ||=
|
6
|
+
@active_support_deprecator ||= begin
|
7
|
+
next_major_version = Money::VERSION.split(".").first.to_i + 1
|
8
|
+
ActiveSupport::Deprecation.new("#{next_major_version}.0.0", "Shopify/Money")
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.deprecate(message)
|
data/lib/money/version.rb
CHANGED
@@ -32,7 +32,8 @@ module RuboCop
|
|
32
32
|
PATTERN
|
33
33
|
|
34
34
|
def on_send(node)
|
35
|
-
money_new(node) do |
|
35
|
+
money_new(node) do |amount, currency_arg|
|
36
|
+
return if amount&.splat_type?
|
36
37
|
return if currency_arg
|
37
38
|
|
38
39
|
add_offense(node, message: 'Money is missing currency argument')
|
@@ -43,8 +43,26 @@ RSpec.describe String do
|
|
43
43
|
it_should_behave_like "an object supporting to_money"
|
44
44
|
|
45
45
|
it "parses an empty string to Money.zero" do
|
46
|
-
expect(
|
47
|
-
|
46
|
+
expect("".to_money("USD")).to eq(Money.new(0, "USD"))
|
47
|
+
|
48
|
+
configure(legacy_deprecations: true) do
|
49
|
+
expect(Money).to receive(:deprecate).once
|
50
|
+
expect(" ".to_money("CAD")).to eq(Money.new(0, "CAD"))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "#to_money to handle thousands delimiters" do
|
55
|
+
configure(legacy_deprecations: true) do
|
56
|
+
expect(Money).to receive(:deprecate).exactly(4).times
|
57
|
+
expect("29.000".to_money("USD")).to eq(Money.new("29000", "USD"))
|
58
|
+
expect("29.000,00".to_money("USD")).to eq(Money.new("29000", "USD"))
|
59
|
+
expect("29,000".to_money("USD")).to eq(Money.new("29000", "USD"))
|
60
|
+
expect("29,000.00".to_money("USD")).to eq(Money.new("29000", "USD"))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "#to_money should behave like Money.new with three decimal places amounts" do
|
65
|
+
expect("29.000".to_money("USD")).to eq(Money.new("29.00", "USD"))
|
48
66
|
end
|
49
67
|
end
|
50
68
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe "deprecations" do
|
5
|
+
it "has the deprecation_horizon as the next major release" do
|
6
|
+
allow(Money).to receive(:const_get).with('VERSION').and_return("1.2.3")
|
7
|
+
expect(Money.active_support_deprecator.deprecation_horizon).to eq("2.0.0")
|
8
|
+
end
|
9
|
+
end
|
@@ -26,6 +26,13 @@ RSpec.describe RuboCop::Cop::Money::MissingCurrency do
|
|
26
26
|
RUBY
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'does not register an offense for Money.new with splat argument' do
|
30
|
+
expect_no_offenses(<<~RUBY)
|
31
|
+
value_and_currency = [1, 'CAD']
|
32
|
+
Money.new(*value_and_currency)
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
29
36
|
it 'registers an offense and corrects for Money.new without a currency argument' do
|
30
37
|
expect_offense(<<~RUBY)
|
31
38
|
Money.new
|
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- spec/core_extensions_spec.rb
|
150
150
|
- spec/currency/loader_spec.rb
|
151
151
|
- spec/currency_spec.rb
|
152
|
+
- spec/deprecations_spec.rb
|
152
153
|
- spec/helpers_spec.rb
|
153
154
|
- spec/money_column_spec.rb
|
154
155
|
- spec/money_spec.rb
|
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
186
|
- !ruby/object:Gem::Version
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
|
-
rubygems_version: 3.4.
|
189
|
+
rubygems_version: 3.4.17
|
189
190
|
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: Shopify's money gem
|
@@ -195,6 +196,7 @@ test_files:
|
|
195
196
|
- spec/core_extensions_spec.rb
|
196
197
|
- spec/currency/loader_spec.rb
|
197
198
|
- spec/currency_spec.rb
|
199
|
+
- spec/deprecations_spec.rb
|
198
200
|
- spec/helpers_spec.rb
|
199
201
|
- spec/money_column_spec.rb
|
200
202
|
- spec/money_spec.rb
|