shopify-money 0.12.0 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/Gemfile +2 -1
  4. data/README.md +20 -1
  5. data/Rakefile +1 -0
  6. data/bin/console +1 -0
  7. data/config/currency_iso.json +1 -1
  8. data/dev.yml +1 -1
  9. data/lib/money.rb +4 -0
  10. data/lib/money/allocator.rb +144 -0
  11. data/lib/money/core_extensions.rb +1 -0
  12. data/lib/money/currency.rb +1 -0
  13. data/lib/money/currency/loader.rb +1 -0
  14. data/lib/money/deprecations.rb +1 -0
  15. data/lib/money/errors.rb +1 -0
  16. data/lib/money/helpers.rb +5 -15
  17. data/lib/money/money.rb +8 -111
  18. data/lib/money/null_currency.rb +1 -0
  19. data/lib/money/version.rb +2 -1
  20. data/lib/money_accessor.rb +1 -0
  21. data/lib/money_column.rb +1 -0
  22. data/lib/money_column/active_record_hooks.rb +2 -1
  23. data/lib/money_column/active_record_type.rb +1 -0
  24. data/lib/money_column/railtie.rb +1 -0
  25. data/lib/rubocop/cop/money.rb +3 -0
  26. data/lib/rubocop/cop/money/missing_currency.rb +75 -0
  27. data/lib/shopify-money.rb +2 -0
  28. data/money.gemspec +7 -3
  29. data/spec/accounting_money_parser_spec.rb +1 -0
  30. data/spec/allocator_spec.rb +148 -0
  31. data/spec/core_extensions_spec.rb +2 -1
  32. data/spec/currency/loader_spec.rb +1 -0
  33. data/spec/currency_spec.rb +1 -0
  34. data/spec/helpers_spec.rb +1 -6
  35. data/spec/money_accessor_spec.rb +1 -0
  36. data/spec/money_column_spec.rb +1 -0
  37. data/spec/money_parser_spec.rb +1 -0
  38. data/spec/money_spec.rb +13 -96
  39. data/spec/null_currency_spec.rb +1 -0
  40. data/spec/rubocop/cop/money/missing_currency_spec.rb +108 -0
  41. data/spec/rubocop_helper.rb +10 -0
  42. data/spec/schema.rb +1 -0
  43. data/spec/spec_helper.rb +1 -5
  44. metadata +20 -24
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "NullCurrency" do
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../rubocop_helper'
4
+ require 'rubocop/cop/money/missing_currency'
5
+
6
+ RSpec.describe RuboCop::Cop::Money::MissingCurrency do
7
+ subject(:cop) { described_class.new(config) }
8
+
9
+ let(:config) { RuboCop::Config.new }
10
+
11
+ describe '#on_send' do
12
+ it 'registers an offense for Money.new without a currency argument' do
13
+ expect_offense(<<~RUBY)
14
+ Money.new(1)
15
+ ^^^^^^^^^^^^ Money is missing currency argument
16
+ RUBY
17
+ end
18
+
19
+ it 'does not register an offense for Money.new with currency argument' do
20
+ expect_no_offenses(<<~RUBY)
21
+ Money.new(1, 'CAD')
22
+ RUBY
23
+ end
24
+
25
+ it 'registers an offense for Money.new without a currency argument' do
26
+ expect_offense(<<~RUBY)
27
+ Money.new
28
+ ^^^^^^^^^ Money is missing currency argument
29
+ RUBY
30
+ end
31
+
32
+ it 'registers an offense for Money.from_amount without a currency argument' do
33
+ expect_offense(<<~RUBY)
34
+ Money.from_amount(1)
35
+ ^^^^^^^^^^^^^^^^^^^^ Money is missing currency argument
36
+ RUBY
37
+ end
38
+
39
+ it 'does not register an offense for Money.from_amount with currency argument' do
40
+ expect_no_offenses(<<~RUBY)
41
+ Money.from_amount(1, 'CAD')
42
+ RUBY
43
+ end
44
+
45
+ it 'registers an offense for Money.from_cents without a currency argument' do
46
+ expect_offense(<<~RUBY)
47
+ Money.from_cents(1)
48
+ ^^^^^^^^^^^^^^^^^^^ Money is missing currency argument
49
+ RUBY
50
+ end
51
+
52
+ it 'does not register an offense for Money.from_cents with currency argument' do
53
+ expect_no_offenses(<<~RUBY)
54
+ Money.from_cents(1, 'CAD')
55
+ RUBY
56
+ end
57
+
58
+ it 'registers an offense for to_money without a currency argument' do
59
+ expect_offense(<<~RUBY)
60
+ '1'.to_money
61
+ ^^^^^^^^^^^^ to_money is missing currency argument
62
+ RUBY
63
+ end
64
+
65
+ it 'does not register an offense for to_money with currency argument' do
66
+ expect_no_offenses(<<~RUBY)
67
+ '1'.to_money('CAD')
68
+ RUBY
69
+ end
70
+
71
+ it 'registers an offense for to_money block pass form' do
72
+ expect_offense(<<~RUBY)
73
+ ['1'].map(&:to_money)
74
+ ^^^^^^^^^^^^^^^^^^^^^ to_money is missing currency argument
75
+ RUBY
76
+ end
77
+ end
78
+
79
+ describe '#autocorrect' do
80
+ let(:config) do
81
+ RuboCop::Config.new(
82
+ 'Money/MissingCurrency' => {
83
+ 'ReplacementCurrency' => 'CAD'
84
+ }
85
+ )
86
+ end
87
+
88
+ it 'corrects Money.new without currency' do
89
+ new_source = autocorrect_source('Money.new(1)')
90
+ expect(new_source).to eq("Money.new(1, 'CAD')")
91
+ end
92
+
93
+ it 'corrects Money.new without amount or currency' do
94
+ new_source = autocorrect_source('Money.new')
95
+ expect(new_source).to eq("Money.new(0, 'CAD')")
96
+ end
97
+
98
+ it 'corrects to_money without currency' do
99
+ new_source = autocorrect_source('1.to_money')
100
+ expect(new_source).to eq("1.to_money('CAD')")
101
+ end
102
+
103
+ it 'corrects to_money block pass form' do
104
+ new_source = autocorrect_source("['1'].map(&:to_money)")
105
+ expect(new_source).to eq("['1'].map { |x| x.to_money('CAD') }")
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ require 'rubocop'
6
+ require 'rubocop/rspec/support'
7
+
8
+ RSpec.configure do |config|
9
+ config.include RuboCop::RSpec::ExpectOffense
10
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ActiveRecord::Schema.define do
2
3
  create_table "money_records", :force => true do |t|
3
4
  t.decimal "price", precision: 20, scale: 3, default: '0.000'
@@ -1,14 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'simplecov'
2
3
  SimpleCov.minimum_coverage 100
3
4
  SimpleCov.start do
4
5
  add_filter "/spec/"
5
6
  end
6
7
 
7
- if ENV['CI'] == 'true'
8
- require 'codecov'
9
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
10
- end
11
-
12
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
14
10
 
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.12.0
4
+ version: 0.14.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: 2019-06-10 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '6.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '6.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.3.6
89
+ version: 1.4.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.3.6
97
- - !ruby/object:Gem::Dependency
98
- name: bigdecimal
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.3.2
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.3.2
96
+ version: 1.4.2
111
97
  description: Manage money in Shopify with a class that wont lose pennies during division!
112
98
  email: gems@shopify.com
113
99
  executables:
@@ -131,6 +117,7 @@ files:
131
117
  - dev.yml
132
118
  - lib/money.rb
133
119
  - lib/money/accounting_money_parser.rb
120
+ - lib/money/allocator.rb
134
121
  - lib/money/core_extensions.rb
135
122
  - lib/money/currency.rb
136
123
  - lib/money/currency/loader.rb
@@ -146,8 +133,12 @@ files:
146
133
  - lib/money_column/active_record_hooks.rb
147
134
  - lib/money_column/active_record_type.rb
148
135
  - lib/money_column/railtie.rb
136
+ - lib/rubocop/cop/money.rb
137
+ - lib/rubocop/cop/money/missing_currency.rb
138
+ - lib/shopify-money.rb
149
139
  - money.gemspec
150
140
  - spec/accounting_money_parser_spec.rb
141
+ - spec/allocator_spec.rb
151
142
  - spec/core_extensions_spec.rb
152
143
  - spec/currency/loader_spec.rb
153
144
  - spec/currency_spec.rb
@@ -157,12 +148,15 @@ files:
157
148
  - spec/money_parser_spec.rb
158
149
  - spec/money_spec.rb
159
150
  - spec/null_currency_spec.rb
151
+ - spec/rubocop/cop/money/missing_currency_spec.rb
152
+ - spec/rubocop_helper.rb
160
153
  - spec/schema.rb
161
154
  - spec/spec_helper.rb
162
155
  homepage: https://github.com/Shopify/money
163
156
  licenses:
164
157
  - MIT
165
- metadata: {}
158
+ metadata:
159
+ allowed_push_host: https://rubygems.org
166
160
  post_install_message:
167
161
  rdoc_options: []
168
162
  require_paths:
@@ -171,20 +165,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
165
  requirements:
172
166
  - - ">="
173
167
  - !ruby/object:Gem::Version
174
- version: '0'
168
+ version: '2.6'
175
169
  required_rubygems_version: !ruby/object:Gem::Requirement
176
170
  requirements:
177
171
  - - ">="
178
172
  - !ruby/object:Gem::Version
179
173
  version: '0'
180
174
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.7.6
175
+ rubygems_version: 3.0.3
183
176
  signing_key:
184
177
  specification_version: 4
185
178
  summary: Shopify's money gem
186
179
  test_files:
187
180
  - spec/accounting_money_parser_spec.rb
181
+ - spec/allocator_spec.rb
188
182
  - spec/core_extensions_spec.rb
189
183
  - spec/currency/loader_spec.rb
190
184
  - spec/currency_spec.rb
@@ -194,5 +188,7 @@ test_files:
194
188
  - spec/money_parser_spec.rb
195
189
  - spec/money_spec.rb
196
190
  - spec/null_currency_spec.rb
191
+ - spec/rubocop/cop/money/missing_currency_spec.rb
192
+ - spec/rubocop_helper.rb
197
193
  - spec/schema.rb
198
194
  - spec/spec_helper.rb