money-rails 1.7.0 → 1.8.0

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: 248e9756e9e93e82ed71a92426635e8864412a66
4
- data.tar.gz: b985a0e0926babc02c77bd3ece23927c261ccaab
3
+ metadata.gz: 73ee4855c001933ab0c12f74417f5696a856dbc9
4
+ data.tar.gz: a733be5b1554565d6142bcf2ab047ed8290c176f
5
5
  SHA512:
6
- metadata.gz: ea054a49148d15a90b373c61df52d73e2598cd67d06e9ffc79dea67e515e6038a365d45f924b09133b90c804311cd9050432e39add9259354823f1f6e0950171
7
- data.tar.gz: b53220b8d3e692f983f556a264a9045b5b09d5361a578fa12ce500df96853d58f71e01b927250528b7447a57b5d60be60fbc0d896eec4b3fc440efb2d839aee4
6
+ metadata.gz: 2478a1cab8317060f5ae05c8e3756a465b621e014e0156aa45a420fabfea85d2f8bbd7ea5d1deaaabbd7b33f4105bea382d7cf6759608b1634738f4b9467aa2c
7
+ data.tar.gz: 08e5e5e699fbd4e7ffd5a09a1565a5c92197369b5cbead24184f0899affcbf9138d57e7358def34d11be25b6b593edb6aad12641ac315fb8b4e3b8c84e094f26
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.0
4
+
5
+ - Ruby 2.4 support
6
+ - Upgrade Money dependency from 6.7 to 6.8.1
7
+ - Upgrade Monetize dependency from 1.4.0 to 1.6.0
8
+ - Raise `MoneyRails::Error` instead of exposing Money and Monetize errors
9
+
3
10
  ## 1.7.0
4
11
 
5
12
  - Rails 5 support
data/README.md CHANGED
@@ -91,7 +91,8 @@ class MonetizeProduct < ActiveRecord::Migration
91
91
  # OR
92
92
 
93
93
  change_table :products do |t|
94
- t.money :price
94
+ t.money :price # Rails 3
95
+ t.monetize :price # Rails 4x and above
95
96
  end
96
97
  end
97
98
  end
@@ -141,6 +142,16 @@ product.optional_price # => nil
141
142
  product.optional_price_cents # => nil
142
143
  ```
143
144
 
145
+ #### Allow large numbers
146
+
147
+ If you foresee that you will be saving large values (range is -2147483648 to +2147483647 for Postgres), increase your integer column limit to bigint:
148
+
149
+ ```ruby
150
+ def change
151
+ change_column :products, :price_cents, :integer, limit: 8
152
+ end
153
+ ```
154
+
144
155
  #### Numericality validation options
145
156
 
146
157
  You can also pass along
@@ -244,6 +255,19 @@ MoneyRails.configure do |config|
244
255
  end
245
256
  ```
246
257
 
258
+ If you need to set the default currency on a per-request basis, such as in a
259
+ multi-tenant application, you may use a lambda to lazy-load the default currency
260
+ from a field in a configuration model called `Tenant` in this example:
261
+
262
+ ```ruby
263
+ # config/initializers/money.rb
264
+ MoneyRails.configure do |config|
265
+
266
+ # set the default currency based on client configuration
267
+ config.default_currency = -> { Tenant.current.default_currency }
268
+ end
269
+ ```
270
+
247
271
  In many cases this is not enough, so there are some other options to
248
272
  meet your needs.
249
273
 
@@ -5,6 +5,7 @@ require "money-rails/configuration"
5
5
  require "money-rails/money"
6
6
  require "money-rails/version"
7
7
  require 'money-rails/hooks'
8
+ require 'money-rails/errors'
8
9
 
9
10
  module MoneyRails
10
11
  extend Configuration
@@ -5,7 +5,7 @@ require 'active_support/deprecation/reporting'
5
5
  module MoneyRails
6
6
  module ActiveRecord
7
7
  module Monetizable
8
- class ReadOnlyCurrencyException < StandardError; end
8
+ class ReadOnlyCurrencyException < MoneyRails::Error; end
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  module ClassMethods
@@ -232,11 +232,8 @@ module MoneyRails
232
232
  money = value.to_money(public_send("currency_for_#{name}"))
233
233
  rescue NoMethodError
234
234
  return nil
235
- rescue ArgumentError
236
- raise if MoneyRails.raise_error_on_money_parsing
237
- return nil
238
- rescue Money::Currency::UnknownCurrency
239
- raise if MoneyRails.raise_error_on_money_parsing
235
+ rescue Money::Currency::UnknownCurrency, Monetize::ParseError => e
236
+ raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
240
237
  return nil
241
238
  end
242
239
  end
@@ -0,0 +1,3 @@
1
+ module MoneyRails
2
+ class Error < StandardError; end
3
+ end
@@ -41,8 +41,8 @@ class Money
41
41
  when object.respond_to?(:to_money) then
42
42
  begin
43
43
  object.to_money.mongoize
44
- rescue ArgumentError, Money::Currency::UnknownCurrency
45
- raise if MoneyRails.raise_error_on_money_parsing
44
+ rescue Money::Currency::UnknownCurrency, Monetize::ParseError => e
45
+ raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
46
46
  nil
47
47
  end
48
48
  else object
@@ -25,8 +25,8 @@ class Money
25
25
  when object.respond_to?(:to_money)
26
26
  begin
27
27
  serialize(object.to_money)
28
- rescue ArgumentError
29
- raise if MoneyRails.raise_error_on_money_parsing
28
+ rescue Monetize::ParseError => e
29
+ raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
30
30
  nil
31
31
  end
32
32
  else nil
@@ -1,3 +1,3 @@
1
1
  module MoneyRails
2
- VERSION = '1.7.0'
2
+ VERSION = '1.8.0'
3
3
  end
@@ -26,8 +26,8 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.require_path = "lib"
28
28
 
29
- s.add_dependency "money", "~> 6.7"
30
- s.add_dependency "monetize", "~> 1.4.0"
29
+ s.add_dependency "money", "~> 6.8.1"
30
+ s.add_dependency "monetize", "~> 1.6.0"
31
31
  s.add_dependency "activesupport", ">= 3.0"
32
32
  s.add_dependency "railties", ">= 3.0"
33
33
  s.add_dependency "mime-types", "< 3" if RUBY_VERSION < '2.0' # mime-types > 3 depends on mime-types-data, which doesn't support ruby 1.9
@@ -154,7 +154,7 @@ if defined? ActiveRecord
154
154
  after { MoneyRails.raise_error_on_money_parsing = false }
155
155
 
156
156
  it "raises exception when a String value with hyphen is assigned" do
157
- expect { product.accessor_price = "10-235" }.to raise_error ArgumentError
157
+ expect { product.accessor_price = "10-235" }.to raise_error MoneyRails::Error
158
158
  end
159
159
 
160
160
  it "raises an exception if it can't change currency" do
@@ -935,17 +935,17 @@ if defined? ActiveRecord
935
935
  before { MoneyRails.raise_error_on_money_parsing = true }
936
936
  after { MoneyRails.raise_error_on_money_parsing = false }
937
937
 
938
- it "raises an ArgumentError when given an invalid value" do
938
+ it "raises a MoneyRails::Error when given an invalid value" do
939
939
  expect {
940
940
  product.write_monetized :price, :price_cents, '10-50', false, nil, {}
941
- }.to raise_error(ArgumentError)
941
+ }.to raise_error(MoneyRails::Error)
942
942
  end
943
943
 
944
- it "raises a Money::Currency::UnknownCurrency error when trying to set invalid currency" do
944
+ it "raises a MoneyRails::Error error when trying to set invalid currency" do
945
945
  allow(product).to receive(:currency_for_price).and_return('INVALID_CURRENCY')
946
946
  expect {
947
947
  product.write_monetized :price, :price_cents, 10, false, nil, {}
948
- }.to raise_error(Money::Currency::UnknownCurrency)
948
+ }.to raise_error(MoneyRails::Error)
949
949
  end
950
950
  end
951
951
 
@@ -956,7 +956,7 @@ if defined? ActiveRecord
956
956
  expect(product.price).to eq(old_price_value)
957
957
  end
958
958
 
959
- it "raises a Money::Currency::UnknownCurrency error when trying to set invalid currency" do
959
+ it "raises a MoneyRails::Error error when trying to set invalid currency" do
960
960
  allow(product).to receive(:currency_for_price).and_return('INVALID_CURRENCY')
961
961
  product.write_monetized :price, :price_cents, 10, false, nil, {}
962
962
 
@@ -41,11 +41,11 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^5(.*)/
41
41
  after { MoneyRails.raise_error_on_money_parsing = false }
42
42
 
43
43
  it "raises exception if the mongoized value is a String with a hyphen" do
44
- expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
44
+ expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
45
45
  end
46
46
 
47
47
  it "raises exception if the mongoized value is a String with an unknown currency" do
48
- expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
48
+ expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
49
49
  end
50
50
  end
51
51
 
@@ -46,11 +46,11 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
46
46
  after { MoneyRails.raise_error_on_money_parsing = false }
47
47
 
48
48
  it "raises exception if the mongoized value is a String with a hyphen" do
49
- expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
49
+ expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
50
50
  end
51
51
 
52
52
  it "raises exception if the mongoized value is a String with an unknown currency" do
53
- expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
53
+ expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
54
54
  end
55
55
  end
56
56
 
@@ -46,11 +46,11 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
46
46
  after { MoneyRails.raise_error_on_money_parsing = false }
47
47
 
48
48
  it "raises exception if the mongoized value is a String with a hyphen" do
49
- expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
49
+ expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
50
50
  end
51
51
 
52
52
  it "raises exception if the mongoized value is a String with an unknown currency" do
53
- expect { priceable_from_string_with_unknown_currency }.to raise_error ArgumentError
53
+ expect { priceable_from_string_with_unknown_currency }.to raise_error MoneyRails::Error
54
54
  end
55
55
  end
56
56
 
@@ -50,7 +50,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
50
50
  after { MoneyRails.raise_error_on_money_parsing = false }
51
51
 
52
52
  it "raises exception if the mongoized value is a String with a hyphen" do
53
- expect { priceable_from_string_with_hyphen }.to raise_error ArgumentError
53
+ expect { priceable_from_string_with_hyphen }.to raise_error MoneyRails::Error
54
54
  end
55
55
  end
56
56
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Loupasakis
@@ -10,126 +10,112 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-31 00:00:00.000000000 Z
13
+ date: 2017-01-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: money
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '6.7'
21
+ version: 6.8.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
- version: '6.7'
28
+ version: 6.8.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: monetize
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 1.4.0
35
+ version: 1.6.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
- version: 1.4.0
42
+ version: 1.6.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: activesupport
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '3.0'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '3.0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: railties
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '3.0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '3.0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rails
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ">="
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3.0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ">="
82
+ - - '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3.0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rspec-rails
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - "~>"
89
+ - - ~>
90
90
  - !ruby/object:Gem::Version
91
91
  version: '3.0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - "~>"
96
+ - - ~>
97
97
  - !ruby/object:Gem::Version
98
98
  version: '3.0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: database_cleaner
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: 0.8.0
106
- - - "<"
106
+ - - <
107
107
  - !ruby/object:Gem::Version
108
108
  version: 1.4.0
109
109
  type: :development
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ">="
113
+ - - '>='
114
114
  - !ruby/object:Gem::Version
115
115
  version: 0.8.0
116
- - - "<"
116
+ - - <
117
117
  - !ruby/object:Gem::Version
118
118
  version: 1.4.0
119
- - !ruby/object:Gem::Dependency
120
- name: test-unit
121
- requirement: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: '3.0'
126
- type: :development
127
- prerelease: false
128
- version_requirements: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: '3.0'
133
119
  description: This library provides integration of RubyMoney - Money gem with Rails
134
120
  email:
135
121
  - alup.rubymoney@gmail.com
@@ -137,14 +123,8 @@ executables: []
137
123
  extensions: []
138
124
  extra_rdoc_files: []
139
125
  files:
140
- - CHANGELOG.md
141
- - LICENSE
142
- - README.md
143
- - Rakefile
144
- - config/locales/money.en.yml
145
126
  - lib/generators/money_rails/initializer_generator.rb
146
127
  - lib/generators/templates/money.rb
147
- - lib/money-rails.rb
148
128
  - lib/money-rails/active_model/validator.rb
149
129
  - lib/money-rails/active_record/migration_extensions/options_extractor.rb
150
130
  - lib/money-rails/active_record/migration_extensions/schema_statements.rb
@@ -154,6 +134,7 @@ files:
154
134
  - lib/money-rails/active_record/monetizable.rb
155
135
  - lib/money-rails/configuration.rb
156
136
  - lib/money-rails/engine.rb
137
+ - lib/money-rails/errors.rb
157
138
  - lib/money-rails/helpers/action_view_extension.rb
158
139
  - lib/money-rails/hooks.rb
159
140
  - lib/money-rails/money.rb
@@ -163,13 +144,11 @@ files:
163
144
  - lib/money-rails/railtie.rb
164
145
  - lib/money-rails/test_helpers.rb
165
146
  - lib/money-rails/version.rb
166
- - money-rails.gemspec
147
+ - lib/money-rails.rb
167
148
  - spec/active_record/migration_extensions/schema_statements_spec.rb
168
149
  - spec/active_record/migration_extensions/table_spec.rb
169
150
  - spec/active_record/monetizable_spec.rb
170
151
  - spec/configuration_spec.rb
171
- - spec/dummy/README.rdoc
172
- - spec/dummy/Rakefile
173
152
  - spec/dummy/app/assets/javascripts/application.js
174
153
  - spec/dummy/app/assets/stylesheets/application.css
175
154
  - spec/dummy/app/controllers/application_controller.rb
@@ -180,7 +159,6 @@ files:
180
159
  - spec/dummy/app/models/service.rb
181
160
  - spec/dummy/app/models/transaction.rb
182
161
  - spec/dummy/app/views/layouts/application.html.erb
183
- - spec/dummy/config.ru
184
162
  - spec/dummy/config/application.rb
185
163
  - spec/dummy/config/boot.rb
186
164
  - spec/dummy/config/database.yml
@@ -201,6 +179,7 @@ files:
201
179
  - spec/dummy/config/locales/it.yml
202
180
  - spec/dummy/config/mongoid.yml
203
181
  - spec/dummy/config/routes.rb
182
+ - spec/dummy/config.ru
204
183
  - spec/dummy/db/migrate/20120331190108_create_products.rb
205
184
  - spec/dummy/db/migrate/20120402080348_add_bonus_cents_to_product.rb
206
185
  - spec/dummy/db/migrate/20120524052716_create_services.rb
@@ -223,6 +202,8 @@ files:
223
202
  - spec/dummy/public/422.html
224
203
  - spec/dummy/public/500.html
225
204
  - spec/dummy/public/favicon.ico
205
+ - spec/dummy/Rakefile
206
+ - spec/dummy/README.rdoc
226
207
  - spec/dummy/script/rails
227
208
  - spec/helpers/action_view_extension_spec.rb
228
209
  - spec/helpers/form_helper_spec.rb
@@ -233,6 +214,12 @@ files:
233
214
  - spec/spec_helper.rb
234
215
  - spec/support/database_cleaner.rb
235
216
  - spec/test_helpers_spec.rb
217
+ - config/locales/money.en.yml
218
+ - CHANGELOG.md
219
+ - LICENSE
220
+ - README.md
221
+ - Rakefile
222
+ - money-rails.gemspec
236
223
  homepage: https://github.com/RubyMoney/money-rails
237
224
  licenses:
238
225
  - MIT
@@ -243,17 +230,17 @@ require_paths:
243
230
  - lib
244
231
  required_ruby_version: !ruby/object:Gem::Requirement
245
232
  requirements:
246
- - - ">="
233
+ - - '>='
247
234
  - !ruby/object:Gem::Version
248
235
  version: '0'
249
236
  required_rubygems_version: !ruby/object:Gem::Requirement
250
237
  requirements:
251
- - - ">="
238
+ - - '>='
252
239
  - !ruby/object:Gem::Version
253
240
  version: '0'
254
241
  requirements: []
255
242
  rubyforge_project:
256
- rubygems_version: 2.5.1
243
+ rubygems_version: 2.0.14.1
257
244
  signing_key:
258
245
  specification_version: 4
259
246
  summary: Money gem integration with Rails
@@ -262,8 +249,6 @@ test_files:
262
249
  - spec/active_record/migration_extensions/table_spec.rb
263
250
  - spec/active_record/monetizable_spec.rb
264
251
  - spec/configuration_spec.rb
265
- - spec/dummy/README.rdoc
266
- - spec/dummy/Rakefile
267
252
  - spec/dummy/app/assets/javascripts/application.js
268
253
  - spec/dummy/app/assets/stylesheets/application.css
269
254
  - spec/dummy/app/controllers/application_controller.rb
@@ -274,7 +259,6 @@ test_files:
274
259
  - spec/dummy/app/models/service.rb
275
260
  - spec/dummy/app/models/transaction.rb
276
261
  - spec/dummy/app/views/layouts/application.html.erb
277
- - spec/dummy/config.ru
278
262
  - spec/dummy/config/application.rb
279
263
  - spec/dummy/config/boot.rb
280
264
  - spec/dummy/config/database.yml
@@ -295,6 +279,7 @@ test_files:
295
279
  - spec/dummy/config/locales/it.yml
296
280
  - spec/dummy/config/mongoid.yml
297
281
  - spec/dummy/config/routes.rb
282
+ - spec/dummy/config.ru
298
283
  - spec/dummy/db/migrate/20120331190108_create_products.rb
299
284
  - spec/dummy/db/migrate/20120402080348_add_bonus_cents_to_product.rb
300
285
  - spec/dummy/db/migrate/20120524052716_create_services.rb
@@ -317,6 +302,8 @@ test_files:
317
302
  - spec/dummy/public/422.html
318
303
  - spec/dummy/public/500.html
319
304
  - spec/dummy/public/favicon.ico
305
+ - spec/dummy/Rakefile
306
+ - spec/dummy/README.rdoc
320
307
  - spec/dummy/script/rails
321
308
  - spec/helpers/action_view_extension_spec.rb
322
309
  - spec/helpers/form_helper_spec.rb