money-rails 1.12.0 → 1.13.4

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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
3
+ if defined?(Mongoid) && ::Mongoid::VERSION.split('.').first.to_i > 2
4
4
 
5
5
  describe Money do
6
6
  let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
@@ -8,12 +8,15 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
8
8
  let(:priceable_from_num) { Priceable.create(price: 1) }
9
9
  let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
10
  let(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
11
+ let(:priceable_from_blank_strings_hash) {
12
+ Priceable.create(price: {cents: '', currency_iso: ''})
13
+ }
11
14
  let(:priceable_from_hash_with_indifferent_access) {
12
15
  Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
13
16
  }
14
17
  let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
15
18
  let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
16
- 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')) }
17
20
  let(:priceable_with_hash_field) {
18
21
  Priceable.create(price_hash: {
19
22
  key1: Money.new(100, "EUR"),
@@ -69,6 +72,10 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
69
72
  expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
70
73
  end
71
74
 
75
+ it "mongoizes a hash of blank strings for cents and currency to nil" do
76
+ expect(priceable_from_blank_strings_hash.price).to eq(nil)
77
+ end
78
+
72
79
  it "correctly mongoizes a HashWithIndifferentAccess of cents and currency" do
73
80
  expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
74
81
  expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
@@ -84,7 +91,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
84
91
  end
85
92
 
86
93
  it "correctly mongoizes a Money object to a hash of cents and currency" do
87
- 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'))
88
95
  expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
89
96
  end
90
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.12.0
4
+ version: 1.13.4
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: 2018-09-16 00:00:00.000000000 Z
13
+ date: 2021-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: money
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 6.12.0
21
+ version: 6.13.2
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.12.0
28
+ version: 6.13.2
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: monetize
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +135,7 @@ files:
135
135
  - LICENSE
136
136
  - README.md
137
137
  - Rakefile
138
+ - config/locales/money.da.yml
138
139
  - config/locales/money.en.yml
139
140
  - lib/generators/money_rails/initializer_generator.rb
140
141
  - lib/generators/templates/money.rb
@@ -165,6 +166,7 @@ files:
165
166
  - spec/configuration_spec.rb
166
167
  - spec/dummy/README.rdoc
167
168
  - spec/dummy/Rakefile
169
+ - spec/dummy/app/assets/config/manifest.js
168
170
  - spec/dummy/app/assets/javascripts/application.js
169
171
  - spec/dummy/app/assets/stylesheets/application.css
170
172
  - spec/dummy/app/controllers/application_controller.rb
@@ -221,9 +223,8 @@ files:
221
223
  - spec/dummy/script/rails
222
224
  - spec/helpers/action_view_extension_spec.rb
223
225
  - spec/helpers/form_helper_spec.rb
224
- - spec/mongoid/five_spec.rb
225
- - spec/mongoid/four_spec.rb
226
- - spec/mongoid/three_spec.rb
226
+ - spec/money_spec.rb
227
+ - spec/mongoid/mongoid_spec.rb
227
228
  - spec/mongoid/two_spec.rb
228
229
  - spec/spec_helper.rb
229
230
  - spec/support/database_cleaner.rb
@@ -231,7 +232,10 @@ files:
231
232
  homepage: https://github.com/RubyMoney/money-rails
232
233
  licenses:
233
234
  - MIT
234
- metadata: {}
235
+ metadata:
236
+ changelog_uri: https://github.com/RubyMoney/money-rails/blob/master/CHANGELOG.md
237
+ source_code_uri: https://github.com/RubyMoney/money-rails/
238
+ bug_tracker_uri: https://github.com/RubyMoney/money-rails/issues
235
239
  post_install_message:
236
240
  rdoc_options: []
237
241
  require_paths:
@@ -247,8 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
251
  - !ruby/object:Gem::Version
248
252
  version: '0'
249
253
  requirements: []
250
- rubyforge_project:
251
- rubygems_version: 2.6.8
254
+ rubygems_version: 3.1.2
252
255
  signing_key:
253
256
  specification_version: 4
254
257
  summary: Money gem integration with Rails
@@ -259,6 +262,7 @@ test_files:
259
262
  - spec/configuration_spec.rb
260
263
  - spec/dummy/README.rdoc
261
264
  - spec/dummy/Rakefile
265
+ - spec/dummy/app/assets/config/manifest.js
262
266
  - spec/dummy/app/assets/javascripts/application.js
263
267
  - spec/dummy/app/assets/stylesheets/application.css
264
268
  - spec/dummy/app/controllers/application_controller.rb
@@ -315,9 +319,8 @@ test_files:
315
319
  - spec/dummy/script/rails
316
320
  - spec/helpers/action_view_extension_spec.rb
317
321
  - spec/helpers/form_helper_spec.rb
318
- - spec/mongoid/five_spec.rb
319
- - spec/mongoid/four_spec.rb
320
- - spec/mongoid/three_spec.rb
322
+ - spec/money_spec.rb
323
+ - spec/mongoid/mongoid_spec.rb
321
324
  - spec/mongoid/two_spec.rb
322
325
  - spec/spec_helper.rb
323
326
  - spec/support/database_cleaner.rb
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined?(Mongoid) && ::Mongoid::VERSION =~ /^5(.*)/
4
-
5
- describe Money do
6
- let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
- let!(:priceable_from_num) { Priceable.create(price: 1) }
8
- let!(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
9
- let!(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
10
- let!(:priceable_from_hash_with_indifferent_access) {
11
- Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
12
- }
13
- let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
14
- let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
15
- let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
16
- let(:priceable_with_hash_field) {
17
- Priceable.create(price_hash: {
18
- key1: Money.new(100, "EUR"),
19
- key2: Money.new(200, "USD")
20
- })
21
- }
22
-
23
- context "mongoize" do
24
- it "correctly mongoizes a Money object to a hash of cents and currency" do
25
- expect(priceable.price.cents).to eq(100)
26
- expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
27
- end
28
-
29
- it "correctly mongoizes a Numeric object to a hash of cents and currency" do
30
- expect(priceable_from_num.price.cents).to eq(100)
31
- expect(priceable_from_num.price.currency).to eq(Money.default_currency)
32
- end
33
-
34
- it "correctly mongoizes a String object to a hash of cents and currency" do
35
- expect(priceable_from_string.price.cents).to eq(100)
36
- expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
37
- end
38
-
39
- context "when MoneyRails.raise_error_on_money_parsing is true" do
40
- before { MoneyRails.raise_error_on_money_parsing = true }
41
- after { MoneyRails.raise_error_on_money_parsing = false }
42
-
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 MoneyRails::Error
45
- end
46
-
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 MoneyRails::Error
49
- end
50
- end
51
-
52
- context "when MoneyRails.raise_error_on_money_parsing is false" do
53
- it "does not correctly mongoize a String with a hyphen in its middle" do
54
- expect(priceable_from_string_with_hyphen.price).to eq(nil)
55
- end
56
-
57
- it "does not correctly mongoize a String with an unknown currency" do
58
- expect(priceable_from_string_with_unknown_currency.price).to eq(nil)
59
- end
60
- end
61
-
62
- it "correctly mongoizes a hash of cents and currency" do
63
- expect(priceable_from_hash.price.cents).to eq(100)
64
- expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
65
- end
66
-
67
- it "correctly mongoizes a HashWithIndifferentAccess of cents and currency" do
68
- expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
69
- expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
70
- end
71
-
72
- context "infinite_precision = true" do
73
- before do
74
- Money.infinite_precision = true
75
- end
76
-
77
- after do
78
- Money.infinite_precision = false
79
- end
80
-
81
- it "correctly mongoizes a Money object to a hash of cents and currency" do
82
- expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
83
- expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
84
- end
85
- end
86
- end
87
-
88
- it "correctly serializes a Hash field containing Money objects" do
89
- expect(priceable_with_hash_field.price_hash[:key1][:cents]).to eq(100)
90
- expect(priceable_with_hash_field.price_hash[:key2][:cents]).to eq(200)
91
- expect(priceable_with_hash_field.price_hash[:key1][:currency_iso]).to eq('EUR')
92
- expect(priceable_with_hash_field.price_hash[:key2][:currency_iso]).to eq('USD')
93
- end
94
-
95
- context "demongoize" do
96
- subject { Priceable.first.price }
97
- it { is_expected.to be_an_instance_of(Money) }
98
- it { is_expected.to eq(Money.new(100, 'EUR')) }
99
-
100
- it "returns 0 cents in default_currency if a nil value was stored" do
101
- nil_priceable = Priceable.create(price: nil)
102
- expect(nil_priceable.price.cents).to eq(0)
103
- expect(nil_priceable.price.currency).to eq(Money.default_currency)
104
- end
105
- it 'returns nil if an unknown value was stored' do
106
- zero_priceable = Priceable.create(price: [])
107
- expect(zero_priceable.price).to be_nil
108
- end
109
- end
110
-
111
- context "evolve" do
112
- it "correctly transforms a Money object into a Mongo friendly value" do
113
- expect(Priceable.where(price: Money.new(100, 'EUR')).first).to eq(priceable)
114
- end
115
- end
116
- end
117
- end
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
4
-
5
- describe Money do
6
- let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
- let(:priceable_from_nil) { Priceable.create(price: nil) }
8
- let(:priceable_from_num) { Priceable.create(price: 1) }
9
- let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
- let(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
11
- let(:priceable_from_hash_with_indifferent_access) {
12
- Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
13
- }
14
- let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
15
- let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
16
- let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
17
- let(:priceable_with_hash_field) {
18
- Priceable.create(price_hash: {
19
- key1: Money.new(100, "EUR"),
20
- key2: Money.new(200, "USD")
21
- })
22
- }
23
-
24
- context "mongoize" do
25
- it "mongoizes correctly nil to nil" do
26
- expect(priceable_from_nil.price).to be_nil
27
- end
28
-
29
- it "mongoizes correctly a Money object to a hash of cents and currency" do
30
- expect(priceable.price.cents).to eq(100)
31
- expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
32
- end
33
-
34
- it "mongoizes correctly a Numeric object to a hash of cents and currency" do
35
- expect(priceable_from_num.price.cents).to eq(100)
36
- expect(priceable_from_num.price.currency).to eq(Money.default_currency)
37
- end
38
-
39
- it "mongoizes correctly a String object to a hash of cents and currency" do
40
- expect(priceable_from_string.price.cents).to eq(100)
41
- expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
42
- end
43
-
44
- context "when MoneyRails.raise_error_on_money_parsing is true" do
45
- before { MoneyRails.raise_error_on_money_parsing = true }
46
- after { MoneyRails.raise_error_on_money_parsing = false }
47
-
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 MoneyRails::Error
50
- end
51
-
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 MoneyRails::Error
54
- end
55
- end
56
-
57
- context "when MoneyRails.raise_error_on_money_parsing is false" do
58
- it "does not mongoizes correctly a String with hyphen in its middle" do
59
- expect(priceable_from_string_with_hyphen.price).to eq(nil)
60
- end
61
-
62
- it "does not mongoize correctly a String with an unknown currency" do
63
- expect(priceable_from_string_with_unknown_currency.price).to eq(nil)
64
- end
65
- end
66
-
67
- it "mongoizes correctly a hash of cents and currency" do
68
- expect(priceable_from_hash.price.cents).to eq(100)
69
- expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
70
- end
71
-
72
- it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
73
- expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
74
- expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
75
- end
76
-
77
- context "infinite_precision = true" do
78
- before do
79
- Money.infinite_precision = true
80
- end
81
-
82
- after do
83
- Money.infinite_precision = false
84
- end
85
-
86
- it "mongoizes correctly a Money object to a hash of cents and currency" do
87
- expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
88
- expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
89
- end
90
- end
91
- end
92
-
93
- it "serializes correctly a Hash field containing Money objects" do
94
- expect(priceable_with_hash_field.price_hash[:key1][:cents]).to eq(100)
95
- expect(priceable_with_hash_field.price_hash[:key2][:cents]).to eq(200)
96
- expect(priceable_with_hash_field.price_hash[:key1][:currency_iso]).to eq('EUR')
97
- expect(priceable_with_hash_field.price_hash[:key2][:currency_iso]).to eq('USD')
98
- end
99
-
100
- context "demongoize" do
101
- subject { Priceable.first.price }
102
- it { is_expected.to be_an_instance_of(Money) }
103
- it { is_expected.to eq(Money.new(100, 'EUR')) }
104
-
105
- it "returns nil if a nil value was stored" do
106
- nil_priceable = Priceable.create(price: nil)
107
- expect(nil_priceable.price).to be_nil
108
- end
109
-
110
- it 'returns nil if an unknown value was stored' do
111
- zero_priceable = Priceable.create(price: [])
112
- expect(zero_priceable.price).to be_nil
113
- end
114
- end
115
-
116
- context "evolve" do
117
- it "transforms correctly a Money object to a Mongo friendly value" do
118
- expect(Priceable.where(price: Money.new(100, 'EUR')).first).to eq(priceable)
119
- end
120
- end
121
- end
122
- end