shopify-money 1.0.2.pre → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/cla.yml +22 -0
- data/.github/workflows/tests.yml +1 -1
- data/README.md +2 -2
- data/lib/money/money.rb +8 -5
- data/lib/money/rails/job_argument_serializer.rb +1 -1
- data/lib/money/version.rb +1 -1
- data/spec/currency_spec.rb +1 -1
- data/spec/money_spec.rb +5 -5
- data/spec/rails/job_argument_serializer_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +6 -6
- data/.github/probots.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae2953d70e905d5f2425b6c334f5e8a920ec749a0e82341739b90dee7c446254
|
4
|
+
data.tar.gz: 42fd32e212f52fb97c366cc39fe8bf462fff7be09ebb54690a6c7a3d80e5c08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538545671ca1a88fd930f5148b0477a2558a6166764439a2a30ff3a7b34f7057fbf510c11f238d44cae13296c2eb81cfd07ffa510bfacae2b8780c49920404ed
|
7
|
+
data.tar.gz: 67944f9355d6b02e61c0e90f9e34cfd3ec7d3adea2f6dfbb45fc88241e38af516ad89726bd13b2e4a211e4adb26741f842904f92095e678808e1e25b871abfde
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [opened, synchronize]
|
6
|
+
issue_comment:
|
7
|
+
types: [created]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cla:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: |
|
13
|
+
(github.event.issue.pull_request
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
16
|
+
)
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
18
|
+
steps:
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
20
|
+
with:
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
data/.github/workflows/tests.yml
CHANGED
data/README.md
CHANGED
@@ -115,8 +115,8 @@ Money::Currency.new("MGA").minor_units # => 1
|
|
115
115
|
## Money column
|
116
116
|
|
117
117
|
Since money internally uses BigDecimal it's logical to use a `decimal` column
|
118
|
-
|
119
|
-
|
118
|
+
for your database. The `money_column` method can generate methods for use with
|
119
|
+
ActiveRecord:
|
120
120
|
|
121
121
|
```ruby
|
122
122
|
create_table :orders do |t|
|
data/lib/money/money.rb
CHANGED
@@ -124,14 +124,14 @@ class Money
|
|
124
124
|
|
125
125
|
def +(other)
|
126
126
|
arithmetic(other) do |money|
|
127
|
-
return self if money.value
|
127
|
+
return self if money.value.zero? && !no_currency?
|
128
128
|
Money.new(value + money.value, calculated_currency(money.currency))
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
def -(other)
|
133
133
|
arithmetic(other) do |money|
|
134
|
-
return self if money.value
|
134
|
+
return self if money.value.zero? && !no_currency?
|
135
135
|
Money.new(value - money.value, calculated_currency(money.currency))
|
136
136
|
end
|
137
137
|
end
|
@@ -232,9 +232,12 @@ class Money
|
|
232
232
|
if units == 0
|
233
233
|
sprintf("%d", rounded_value)
|
234
234
|
else
|
235
|
-
|
236
|
-
|
237
|
-
|
235
|
+
formatted = rounded_value.to_s("F")
|
236
|
+
decimal_digits = formatted.size - formatted.index(".") - 1
|
237
|
+
(units - decimal_digits).times do
|
238
|
+
formatted << '0'
|
239
|
+
end
|
240
|
+
formatted
|
238
241
|
end
|
239
242
|
end
|
240
243
|
alias_method :to_s, :to_fs
|
@@ -4,7 +4,7 @@ class Money
|
|
4
4
|
module Rails
|
5
5
|
class JobArgumentSerializer < ::ActiveJob::Serializers::ObjectSerializer
|
6
6
|
def serialize(money)
|
7
|
-
super("value" => money.value, "currency" => money.currency.iso_code)
|
7
|
+
super("value" => money.value.to_s("F"), "currency" => money.currency.iso_code)
|
8
8
|
end
|
9
9
|
|
10
10
|
def deserialize(hash)
|
data/lib/money/version.rb
CHANGED
data/spec/currency_spec.rb
CHANGED
@@ -80,7 +80,7 @@ RSpec.describe "Currency" do
|
|
80
80
|
describe "#hash" do
|
81
81
|
specify "equal currencies from different loaders have the same hash" do
|
82
82
|
currency_1 = Money::Currency.find('USD')
|
83
|
-
currency_2 =
|
83
|
+
currency_2 = yaml_load(Money::Currency.find('USD').to_yaml)
|
84
84
|
|
85
85
|
expect(currency_1.eql?(currency_2)).to eq(true)
|
86
86
|
expect(currency_1.hash).to eq(currency_2.hash)
|
data/spec/money_spec.rb
CHANGED
@@ -846,17 +846,17 @@ RSpec.describe "Money" do
|
|
846
846
|
|
847
847
|
describe "YAML deserialization" do
|
848
848
|
it "accepts values with currencies" do
|
849
|
-
money =
|
849
|
+
money = yaml_load("--- !ruby/object:Money\nvalue: '750.0'\ncurrency: USD\n")
|
850
850
|
expect(money).to eq(Money.new(750, 'usd'))
|
851
851
|
end
|
852
852
|
|
853
853
|
it "accepts values with null currencies" do
|
854
|
-
money =
|
854
|
+
money = yaml_load("--- !ruby/object:Money\nvalue: '750.0'\ncurrency: XXX\n")
|
855
855
|
expect(money).to eq(Money.new(750))
|
856
856
|
end
|
857
857
|
|
858
858
|
it "accepts serialized NullCurrency objects" do
|
859
|
-
money =
|
859
|
+
money = yaml_load(<<~EOS)
|
860
860
|
---
|
861
861
|
!ruby/object:Money
|
862
862
|
currency: !ruby/object:Money::NullCurrency
|
@@ -879,7 +879,7 @@ RSpec.describe "Money" do
|
|
879
879
|
end
|
880
880
|
|
881
881
|
it "accepts BigDecimal values" do
|
882
|
-
money =
|
882
|
+
money = yaml_load(<<~EOS)
|
883
883
|
---
|
884
884
|
!ruby/object:Money
|
885
885
|
value: !ruby/object:BigDecimal 18:0.75E3
|
@@ -890,7 +890,7 @@ RSpec.describe "Money" do
|
|
890
890
|
end
|
891
891
|
|
892
892
|
it "accepts old float values..." do
|
893
|
-
money =
|
893
|
+
money = yaml_load(<<~EOS)
|
894
894
|
---
|
895
895
|
!ruby/object:Money
|
896
896
|
value: 750.00
|
@@ -9,7 +9,7 @@ RSpec.describe Money::Rails::JobArgumentSerializer do
|
|
9
9
|
serialized_job = job.serialize
|
10
10
|
serialized_value = serialized_job["arguments"][0]["value"]
|
11
11
|
expect(serialized_value["_aj_serialized"]).to eq("Money::Rails::JobArgumentSerializer")
|
12
|
-
expect(serialized_value["value"]).to eq(
|
12
|
+
expect(serialized_value["value"]).to eq("10.21")
|
13
13
|
expect(serialized_value["currency"]).to eq("BRL")
|
14
14
|
|
15
15
|
job2 = MoneyTestJob.deserialize(serialized_job)
|
data/spec/spec_helper.rb
CHANGED
@@ -83,3 +83,9 @@ def configure(default_currency: nil, legacy_json_format: nil, legacy_deprecation
|
|
83
83
|
ensure
|
84
84
|
Money.config = old_config
|
85
85
|
end
|
86
|
+
|
87
|
+
def yaml_load(yaml)
|
88
|
+
return YAML.load(yaml) if Psych::VERSION < '4.0'
|
89
|
+
|
90
|
+
YAML.safe_load(yaml, permitted_classes: [BigDecimal, Money, Money::Currency, Money::NullCurrency])
|
91
|
+
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: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".document"
|
105
|
-
- ".github/
|
105
|
+
- ".github/workflows/cla.yml"
|
106
106
|
- ".github/workflows/tests.yml"
|
107
107
|
- ".gitignore"
|
108
108
|
- ".rspec"
|
@@ -179,11 +179,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '2.6'
|
180
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
181
|
requirements:
|
182
|
-
- - "
|
182
|
+
- - ">="
|
183
183
|
- !ruby/object:Gem::Version
|
184
|
-
version:
|
184
|
+
version: '0'
|
185
185
|
requirements: []
|
186
|
-
rubygems_version: 3.
|
186
|
+
rubygems_version: 3.3.3
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: Shopify's money gem
|
data/.github/probots.yml
DELETED