money-rails 1.13.2 → 1.13.3

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
- SHA1:
3
- metadata.gz: afde9881744906b6e1095808941f25c35882a6cf
4
- data.tar.gz: 8124dc1db10118638c59fbd573d5169a10c856a7
2
+ SHA256:
3
+ metadata.gz: 94253df4c6ac9ec75bfc1b569d6d05a96082846df1c7e2ab61d65cc56cf10183
4
+ data.tar.gz: 8fbcf7e06595b836c03d12d77bba6db42fbf40abc5b1de44e7c6311ffca4f01f
5
5
  SHA512:
6
- metadata.gz: db46b687d7785a6003671c6303256b67a7e97f8eba7ae56ef80839a3b0bd09ec8b01b12131e1cf959066b3b59c31d9812fcd3ab31a551a926f83335909c0458b
7
- data.tar.gz: d40ce1a07d6a8af402c61336b999d8bb41460ec1802df4016fe915613be1e41c6ede7fef65ec8bc711e15b0983dd8a661466a8401e29b15ee581f6734fffb0fe
6
+ metadata.gz: a3f73a3833288cc529da04343d58ce82dabaa3563c61281712a8e5d975f3c60cacce5ff37b9b5422bacbf6f6c0606468643145376521925b9db26281748150fb
7
+ data.tar.gz: 035af0f28d1aae1e28a970938f402a32c5de2eb1abd62bc2d36808f366dfe60f92f06aa4c5dddf9f940f85b20776deb9707def03b65544aedb6c9883dd8c67ac
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.13.3
4
+
5
+ - Add Money#to_hash for JSON serialization
6
+ - Update initializer template with #locale_backend config
7
+ - Rollback support for remove_monetize / remove_money DB helpers
8
+ - Rails 6 support
9
+
3
10
  ## 1.13.2
4
11
 
5
12
  - Make validation compatible with Money.locale_backend
@@ -83,6 +83,29 @@ MoneyRails.configure do |config|
83
83
  # sign_before_symbol: nil
84
84
  # }
85
85
 
86
+ # If you would like to use I18n localization (formatting depends on the
87
+ # locale):
88
+ # config.locale_backend = :i18n
89
+ #
90
+ # Example (using default localization from rails-i18n):
91
+ #
92
+ # I18n.locale = :en
93
+ # Money.new(10_000_00, 'USD').format # => $10,000.00
94
+ # I18n.locale = :es
95
+ # Money.new(10_000_00, 'USD').format # => $10.000,00
96
+ #
97
+ # For the legacy behaviour of "per currency" localization (formatting depends
98
+ # only on currency):
99
+ # config.locale_backend = :currency
100
+ #
101
+ # Example:
102
+ # Money.new(10_000_00, 'USD').format # => $10,000.00
103
+ # Money.new(10_000_00, 'EUR').format # => €10.000,00
104
+ #
105
+ # In case you don't need localization and would like to use default values
106
+ # (can be redefined using config.default_format):
107
+ # config.locale_backend = nil
108
+
86
109
  # Set default raise_error_on_money_parsing option
87
110
  # It will be raise error if assigned different currency
88
111
  # The default value is false
@@ -11,8 +11,8 @@ module MoneyRails
11
11
 
12
12
  def remove_monetize(table_name, accessor, options={})
13
13
  [:amount, :currency].each do |attribute|
14
- column_present, table_name, column_name, _, _ = OptionsExtractor.extract attribute, table_name, accessor, options
15
- remove_column table_name, column_name if column_present
14
+ column_present, table_name, column_name, type, _ = OptionsExtractor.extract attribute, table_name, accessor, options
15
+ remove_column table_name, column_name, type if column_present
16
16
  end
17
17
  end
18
18
  end
@@ -21,4 +21,9 @@ class Money
21
21
  rules
22
22
  end
23
23
  end
24
+
25
+ # This is expected to be called by ActiveSupport when calling as_json an Money object
26
+ def to_hash
27
+ { cents: cents, currency_iso: currency.iso_code.to_s }
28
+ end
24
29
  end
@@ -1,3 +1,3 @@
1
1
  module MoneyRails
2
- VERSION = '1.13.2'
2
+ VERSION = '1.13.3'
3
3
  end
@@ -36,4 +36,10 @@ Gem::Specification.new do |s|
36
36
  s.add_development_dependency "rspec-rails", "~> 3.0"
37
37
  s.add_development_dependency 'database_cleaner', '~> 1.6.1'
38
38
  s.add_development_dependency 'test-unit', '~> 3.0' if RUBY_VERSION >= '2.2'
39
+
40
+ if s.respond_to?(:metadata)
41
+ s.metadata['changelog_uri'] = 'https://github.com/RubyMoney/money-rails/blob/master/CHANGELOG.md'
42
+ s.metadata['source_code_uri'] = 'https://github.com/RubyMoney/money-rails/'
43
+ s.metadata['bug_tracker_uri'] = 'https://github.com/RubyMoney/money-rails/issues'
44
+ end
39
45
  end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Money overrides' do
6
+ describe '.default_formatting_rules' do
7
+ it 'uses defauts set as individual options' do
8
+ allow(MoneyRails::Configuration).to receive(:symbol).and_return('£')
9
+
10
+ expect(Money.default_formatting_rules).to include(symbol: '£')
11
+ end
12
+
13
+ it 'ignores individual options that are nil' do
14
+ allow(MoneyRails::Configuration).to receive(:symbol).and_return(nil)
15
+
16
+ expect(Money.default_formatting_rules.keys).not_to include(:symbol)
17
+ end
18
+
19
+ it 'includes default_format options' do
20
+ allow(MoneyRails::Configuration).to receive(:default_format).and_return(symbol: '£')
21
+
22
+ expect(Money.default_formatting_rules).to include(symbol: '£')
23
+ end
24
+
25
+ it 'gives priority to original defaults' do
26
+ allow(Money).to receive(:orig_default_formatting_rules).and_return(symbol: '£')
27
+ allow(MoneyRails::Configuration).to receive(:symbol).and_return('€')
28
+ allow(MoneyRails::Configuration).to receive(:default_format).and_return(symbol: '€')
29
+
30
+ expect(Money.default_formatting_rules).to include(symbol: '£')
31
+ end
32
+ end
33
+
34
+ describe '#to_hash' do
35
+ it 'returns a hash with JSON representation' do
36
+ expect(Money.new(9_99, 'EUR').to_hash).to eq(cents: 9_99, currency_iso: 'EUR')
37
+ expect(Money.zero('USD').to_hash).to eq(cents: 0, currency_iso: 'USD')
38
+ end
39
+ end
40
+ end
@@ -16,7 +16,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION.split('.').first.to_i > 2
16
16
  }
17
17
  let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
18
18
  let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
19
- let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
19
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal('100.1'), 'EUR')) }
20
20
  let(:priceable_with_hash_field) {
21
21
  Priceable.create(price_hash: {
22
22
  key1: Money.new(100, "EUR"),
@@ -91,7 +91,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION.split('.').first.to_i > 2
91
91
  end
92
92
 
93
93
  it "correctly mongoizes a Money object to a hash of cents and currency" do
94
- expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
94
+ expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal('100.1'))
95
95
  expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
96
96
  end
97
97
  end
@@ -7,7 +7,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
7
7
  let(:priceable_from_nil) { Priceable.create(price: nil) }
8
8
  let(:priceable_from_num) { Priceable.create(price: 1) }
9
9
  let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
- let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
10
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal('100.1'), 'EUR')) }
11
11
  let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
12
12
 
13
13
  context "serialize" do
@@ -40,7 +40,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
40
40
  end
41
41
 
42
42
  it "mongoizes correctly a Money object to a hash of cents and currency" do
43
- expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
43
+ expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal('100.1'))
44
44
  expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
45
45
  end
46
46
  end
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.13.2
4
+ version: 1.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Loupasakis
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-14 00:00:00.000000000 Z
13
+ date: 2019-10-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: money
@@ -165,6 +165,7 @@ files:
165
165
  - spec/configuration_spec.rb
166
166
  - spec/dummy/README.rdoc
167
167
  - spec/dummy/Rakefile
168
+ - spec/dummy/app/assets/config/manifest.js
168
169
  - spec/dummy/app/assets/javascripts/application.js
169
170
  - spec/dummy/app/assets/stylesheets/application.css
170
171
  - spec/dummy/app/controllers/application_controller.rb
@@ -221,6 +222,7 @@ files:
221
222
  - spec/dummy/script/rails
222
223
  - spec/helpers/action_view_extension_spec.rb
223
224
  - spec/helpers/form_helper_spec.rb
225
+ - spec/money_spec.rb
224
226
  - spec/mongoid/mongoid_spec.rb
225
227
  - spec/mongoid/two_spec.rb
226
228
  - spec/spec_helper.rb
@@ -229,7 +231,10 @@ files:
229
231
  homepage: https://github.com/RubyMoney/money-rails
230
232
  licenses:
231
233
  - MIT
232
- metadata: {}
234
+ metadata:
235
+ changelog_uri: https://github.com/RubyMoney/money-rails/blob/master/CHANGELOG.md
236
+ source_code_uri: https://github.com/RubyMoney/money-rails/
237
+ bug_tracker_uri: https://github.com/RubyMoney/money-rails/issues
233
238
  post_install_message:
234
239
  rdoc_options: []
235
240
  require_paths:
@@ -245,8 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
250
  - !ruby/object:Gem::Version
246
251
  version: '0'
247
252
  requirements: []
248
- rubyforge_project:
249
- rubygems_version: 2.6.8
253
+ rubygems_version: 3.0.3
250
254
  signing_key:
251
255
  specification_version: 4
252
256
  summary: Money gem integration with Rails
@@ -257,6 +261,7 @@ test_files:
257
261
  - spec/configuration_spec.rb
258
262
  - spec/dummy/README.rdoc
259
263
  - spec/dummy/Rakefile
264
+ - spec/dummy/app/assets/config/manifest.js
260
265
  - spec/dummy/app/assets/javascripts/application.js
261
266
  - spec/dummy/app/assets/stylesheets/application.css
262
267
  - spec/dummy/app/controllers/application_controller.rb
@@ -313,6 +318,7 @@ test_files:
313
318
  - spec/dummy/script/rails
314
319
  - spec/helpers/action_view_extension_spec.rb
315
320
  - spec/helpers/form_helper_spec.rb
321
+ - spec/money_spec.rb
316
322
  - spec/mongoid/mongoid_spec.rb
317
323
  - spec/mongoid/two_spec.rb
318
324
  - spec/spec_helper.rb