mongoid_money_field 5.2.0 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile.lock +32 -30
- data/lib/mongoid_money_field/rails_admin.rb +1 -1
- data/lib/mongoid_money_field/version.rb +1 -1
- data/spec/money_spec.rb +103 -103
- data/spec/ruby_money_spec.rb +15 -15
- metadata +31 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a6882924fb9cba04e5d3292b92b2a96fb6389c
|
4
|
+
data.tar.gz: 3d2d6209f835ffd23b534245c29f31131c1d4c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbf1cae218d669386c979d2368090612fa39a60527b9c58fc561746d3076053d208c77146a326b043c55a2be0fe355da9a13b5813bedc53bcb4eec3e805c133
|
7
|
+
data.tar.gz: 723bffc2d8933b028452bf4ab14476f1272cffdb95f37fc2ef6fcbb5cacd5cdfde14650d31c549e7aa8f995b79110c1019d74103252b354ecdbd4abf4b74ba96
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid_money_field (5.
|
4
|
+
mongoid_money_field (5.2.1)
|
5
5
|
monetize
|
6
6
|
money (~> 6.1.0.beta1)
|
7
7
|
mongoid (>= 3.0.0)
|
@@ -9,64 +9,66 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (4.0.
|
13
|
-
activesupport (= 4.0.
|
12
|
+
activemodel (4.0.5)
|
13
|
+
activesupport (= 4.0.5)
|
14
14
|
builder (~> 3.1.0)
|
15
|
-
activesupport (4.0.
|
16
|
-
i18n (~> 0.6, >= 0.6.
|
15
|
+
activesupport (4.0.5)
|
16
|
+
i18n (~> 0.6, >= 0.6.9)
|
17
17
|
minitest (~> 4.2)
|
18
18
|
multi_json (~> 1.3)
|
19
19
|
thread_safe (~> 0.1)
|
20
20
|
tzinfo (~> 0.3.37)
|
21
|
-
|
22
|
-
bson (2.2.0)
|
21
|
+
bson (2.3.0)
|
23
22
|
builder (3.1.4)
|
24
|
-
connection_pool (
|
25
|
-
database_cleaner (1.
|
23
|
+
connection_pool (2.0.0)
|
24
|
+
database_cleaner (1.3.0)
|
26
25
|
diff-lcs (1.2.5)
|
27
26
|
docile (1.1.3)
|
28
27
|
i18n (0.6.9)
|
29
28
|
json (1.8.1)
|
30
29
|
minitest (4.7.5)
|
31
|
-
monetize (0.
|
30
|
+
monetize (0.3.0)
|
32
31
|
money (~> 6.1.0.beta1)
|
33
|
-
money (6.1.
|
32
|
+
money (6.1.1)
|
34
33
|
i18n (~> 0.6.4)
|
35
|
-
mongoid (4.0.0.
|
36
|
-
activemodel (
|
37
|
-
moped (~> 2.0.
|
34
|
+
mongoid (4.0.0.rc1)
|
35
|
+
activemodel (~> 4.0.0)
|
36
|
+
moped (~> 2.0.0.rc1)
|
38
37
|
origin (~> 2.1)
|
39
38
|
tzinfo (>= 0.3.37)
|
40
39
|
mongoid-rspec (1.10.0)
|
41
40
|
mongoid (>= 3.0.1)
|
42
41
|
rake
|
43
42
|
rspec (>= 2.14)
|
44
|
-
moped (2.0.0.
|
43
|
+
moped (2.0.0.rc1)
|
45
44
|
bson (~> 2.2)
|
46
|
-
connection_pool (~>
|
45
|
+
connection_pool (~> 2.0)
|
47
46
|
optionable (~> 0.2.0)
|
48
|
-
multi_json (1.
|
47
|
+
multi_json (1.10.1)
|
49
48
|
optionable (0.2.0)
|
50
|
-
origin (2.1.
|
51
|
-
rake (10.
|
49
|
+
origin (2.1.1)
|
50
|
+
rake (10.3.2)
|
52
51
|
rdoc (4.1.1)
|
53
52
|
json (~> 1.4)
|
54
|
-
rspec (
|
55
|
-
rspec-core (~>
|
56
|
-
rspec-expectations (~>
|
57
|
-
rspec-mocks (~>
|
58
|
-
rspec-core (
|
59
|
-
|
60
|
-
|
61
|
-
|
53
|
+
rspec (3.0.0)
|
54
|
+
rspec-core (~> 3.0.0)
|
55
|
+
rspec-expectations (~> 3.0.0)
|
56
|
+
rspec-mocks (~> 3.0.0)
|
57
|
+
rspec-core (3.0.0)
|
58
|
+
rspec-support (~> 3.0.0)
|
59
|
+
rspec-expectations (3.0.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.0.0)
|
62
|
+
rspec-mocks (3.0.1)
|
63
|
+
rspec-support (~> 3.0.0)
|
64
|
+
rspec-support (3.0.0)
|
62
65
|
simplecov (0.8.2)
|
63
66
|
docile (~> 1.1.0)
|
64
67
|
multi_json
|
65
68
|
simplecov-html (~> 0.8.0)
|
66
69
|
simplecov-html (0.8.0)
|
67
|
-
thread_safe (0.
|
68
|
-
|
69
|
-
tzinfo (0.3.38)
|
70
|
+
thread_safe (0.3.4)
|
71
|
+
tzinfo (0.3.39)
|
70
72
|
|
71
73
|
PLATFORMS
|
72
74
|
ruby
|
@@ -31,7 +31,7 @@ module RailsAdmin
|
|
31
31
|
RailsAdmin::Config::Fields::Types::register(self)
|
32
32
|
|
33
33
|
register_instance_option :pretty_value do
|
34
|
-
ret = if value.class.name == 'Hash' && value['cents']
|
34
|
+
ret = if (value.class.name == 'Hash' || value.class.name == 'BSON::Document') && value['cents']
|
35
35
|
"%.2f" % ::Money.new(value['cents'], value['currency_iso']).to_f
|
36
36
|
elsif value.respond_to?(:cents)
|
37
37
|
"%.2f" % value.to_f
|
data/spec/money_spec.rb
CHANGED
@@ -8,16 +8,16 @@ describe Mongoid::MoneyField do
|
|
8
8
|
it 'should be valid to save when field is filled in' do
|
9
9
|
dummy = DummyMoneyRequired.new
|
10
10
|
dummy.price = '$10'
|
11
|
-
dummy.
|
12
|
-
dummy.save.
|
11
|
+
expect(dummy).to be_valid
|
12
|
+
expect(dummy.save).to eq true
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should be not valid to save when field is not filled in' do
|
16
16
|
dummy = DummyMoneyRequired.new
|
17
|
-
dummy.
|
18
|
-
dummy.errors.count.
|
19
|
-
dummy.errors.messages[:price][0].
|
20
|
-
dummy.save.
|
17
|
+
expect(dummy).not_to be_valid
|
18
|
+
expect(dummy.errors.count).to eq 1
|
19
|
+
expect(dummy.errors.messages[:price][0]).to eq "can't be blank"
|
20
|
+
expect(dummy.save).to eq false
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -25,35 +25,35 @@ describe Mongoid::MoneyField do
|
|
25
25
|
it 'should raise the error when value consists non digits' do
|
26
26
|
dummy = DummyNotANumber.new
|
27
27
|
dummy.price = 'incorrect1'
|
28
|
-
dummy.
|
29
|
-
dummy.errors.count.
|
30
|
-
dummy.errors.messages[:price][0].
|
31
|
-
dummy.save.
|
28
|
+
expect(dummy).not_to be_valid
|
29
|
+
expect(dummy.errors.count).to eq 1
|
30
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
31
|
+
expect(dummy.save).to eq false
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should raise the error when value consists more then one decimal separator' do
|
35
35
|
dummy = DummyNotANumber.new
|
36
36
|
dummy.price = '121,212,22'
|
37
|
-
dummy.
|
38
|
-
dummy.errors.count.
|
39
|
-
dummy.errors.messages[:price][0].
|
40
|
-
dummy.save.
|
37
|
+
expect(dummy).not_to be_valid
|
38
|
+
expect(dummy.errors.count).to eq 1
|
39
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
40
|
+
expect(dummy.save).to eq false
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should raise the error when value is not present' do
|
44
44
|
dummy = DummyNotANumber.new
|
45
|
-
dummy.
|
46
|
-
dummy.errors.count.
|
47
|
-
dummy.errors.messages[:price][0].
|
48
|
-
dummy.save.
|
45
|
+
expect(dummy).not_to be_valid
|
46
|
+
expect(dummy.errors.count).to eq 1
|
47
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
48
|
+
expect(dummy.save).to eq false
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should raise the error when value is not present' do
|
52
52
|
dummy = DummyNotANumber.new(price: '')
|
53
|
-
dummy.
|
54
|
-
dummy.errors.count.
|
55
|
-
dummy.errors.messages[:price][0].
|
56
|
-
dummy.save.
|
53
|
+
expect(dummy).not_to be_valid
|
54
|
+
expect(dummy.errors.count).to eq 1
|
55
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
56
|
+
expect(dummy.save).to eq false
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,78 +61,78 @@ describe Mongoid::MoneyField do
|
|
61
61
|
it 'should raise the error when value consists non digits' do
|
62
62
|
dummy = DummyNotANumber.new
|
63
63
|
dummy.price = 'incorrect1'
|
64
|
-
dummy.
|
65
|
-
dummy.errors.count.
|
66
|
-
dummy.errors.messages[:price][0].
|
67
|
-
dummy.save.
|
64
|
+
expect(dummy).not_to be_valid
|
65
|
+
expect(dummy.errors.count).to eq 1
|
66
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
67
|
+
expect(dummy.save).to eq false
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should raise the error when value consists more then one decimal separator' do
|
71
71
|
dummy = DummyNotANumber.new
|
72
72
|
dummy.price = '121,212,22'
|
73
|
-
dummy.
|
74
|
-
dummy.errors.count.
|
75
|
-
dummy.errors.messages[:price][0].
|
76
|
-
dummy.save.
|
73
|
+
expect(dummy).not_to be_valid
|
74
|
+
expect(dummy.errors.count).to eq 1
|
75
|
+
expect(dummy.errors.messages[:price][0]).to eq "is not a number"
|
76
|
+
expect(dummy.save).to eq false
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
describe 'when value should be a positive number' do
|
81
81
|
it 'should raise the error when value lesser than 1' do
|
82
82
|
dummy = DummyPositiveNumber.new(price: '-10')
|
83
|
-
dummy.
|
84
|
-
dummy.errors.count.
|
85
|
-
dummy.errors.messages[:price][0].
|
86
|
-
dummy.save.
|
83
|
+
expect(dummy).not_to be_valid
|
84
|
+
expect(dummy.errors.count).to eq 1
|
85
|
+
expect(dummy.errors.messages[:price][0]).to eq "must be greater than 1"
|
86
|
+
expect(dummy.save).to eq false
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'should raise the error when value lesser than 1' do
|
90
90
|
dummy = DummyPositiveNumber.new(price: '-1000')
|
91
|
-
dummy.
|
92
|
-
dummy.errors.count.
|
93
|
-
dummy.errors.messages[:price][0].
|
94
|
-
dummy.save.
|
91
|
+
expect(dummy).not_to be_valid
|
92
|
+
expect(dummy.errors.count).to eq 1
|
93
|
+
expect(dummy.errors.messages[:price][0]).to eq "must be greater than 1"
|
94
|
+
expect(dummy.save).to eq false
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should raise the error when value lesser than 1' do
|
98
98
|
dummy = DummyPositiveNumber.new(price: '0')
|
99
|
-
dummy.
|
100
|
-
dummy.errors.count.
|
101
|
-
dummy.errors.messages[:price][0].
|
102
|
-
dummy.save.
|
99
|
+
expect(dummy).not_to be_valid
|
100
|
+
expect(dummy.errors.count).to eq 1
|
101
|
+
expect(dummy.errors.messages[:price][0]).to eq "must be greater than 1"
|
102
|
+
expect(dummy.save).to eq false
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should be ok when value is greater than 1' do
|
106
106
|
dummy = DummyPositiveNumber.new(price: '10')
|
107
|
-
dummy.
|
108
|
-
dummy.save.
|
107
|
+
expect(dummy).to be_valid
|
108
|
+
expect(dummy.save).to eq true
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should be ok when value is greater than 1' do
|
112
112
|
dummy = DummyPositiveNumber.new(price: '1000')
|
113
|
-
dummy.
|
114
|
-
dummy.save.
|
113
|
+
expect(dummy).to be_valid
|
114
|
+
expect(dummy.save).to eq true
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should be ok when value is not present' do
|
118
118
|
dummy = DummyPositiveNumber.new(price: '')
|
119
|
-
dummy.
|
120
|
-
dummy.save.
|
119
|
+
expect(dummy).to be_valid
|
120
|
+
expect(dummy.save).to eq true
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
describe 'when both default currency and fixed currency is specified' do
|
125
125
|
it 'should use fixed currency instead of default' do
|
126
126
|
DummyOverrideDefaultCurrency.create!(price: '1.23')
|
127
|
-
DummyOverrideDefaultCurrency.first.price.currency.iso_code.
|
127
|
+
expect(DummyOverrideDefaultCurrency.first.price.currency.iso_code).to eq 'GBP'
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
describe 'when default currency is specified' do
|
132
132
|
it 'should use it instead of Money.default_currency' do
|
133
133
|
DummyWithDefaultCurrency.create!(price: '1.23')
|
134
|
-
DummyWithDefaultCurrency.first.price.currency.iso_code.
|
135
|
-
Money.default_currency.iso_code.
|
134
|
+
expect(DummyWithDefaultCurrency.first.price.currency.iso_code).to eq 'EUR'
|
135
|
+
expect(Money.default_currency.iso_code).to eq 'RUB'
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -140,32 +140,32 @@ describe Mongoid::MoneyField do
|
|
140
140
|
it 'should be persisted normally when set as dollars' do
|
141
141
|
dummy = DummyMoney.new
|
142
142
|
dummy.price = '$10'
|
143
|
-
dummy.save.
|
143
|
+
expect(dummy.save).to eq true
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'should be persisted normally when set as cents' do
|
147
147
|
dummy = DummyMoney.new
|
148
148
|
dummy.price = '$9.99'
|
149
|
-
dummy.save.
|
149
|
+
expect(dummy.save).to eq true
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should be persisted normally when set as Money' do
|
153
153
|
dummy = DummyMoney.new
|
154
154
|
dummy.price = Monetize.parse(1.23)
|
155
|
-
dummy.save.
|
155
|
+
expect(dummy.save).to eq true
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should be possible to set value to nil' do
|
159
159
|
dummy = DummyMoney.new
|
160
160
|
dummy.price = Monetize.parse(1.23)
|
161
|
-
dummy.save.
|
161
|
+
expect(dummy.save).to eq true
|
162
162
|
|
163
163
|
dummy = DummyMoney.first
|
164
|
-
dummy.price.
|
164
|
+
expect(dummy.price).to eq Monetize.parse(1.23)
|
165
165
|
dummy.price = nil
|
166
|
-
dummy.save.
|
166
|
+
expect(dummy.save).to eq true
|
167
167
|
dummy = DummyMoney.first
|
168
|
-
dummy.price.
|
168
|
+
expect(dummy.price).to be_nil
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -176,7 +176,7 @@ describe Mongoid::MoneyField do
|
|
176
176
|
|
177
177
|
it 'should have a Money value that matches the money value that was initially persisted' do
|
178
178
|
dummy = DummyMoney.first
|
179
|
-
dummy.price.
|
179
|
+
expect(dummy.price).to eq Monetize.parse('9.99')
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
@@ -189,7 +189,7 @@ describe Mongoid::MoneyField do
|
|
189
189
|
|
190
190
|
it 'should have a Money value that matches the money value that was initially persisted' do
|
191
191
|
dummy = DummyMoney.first
|
192
|
-
dummy.price.cents.
|
192
|
+
expect(dummy.price.cents).to eq 123
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
@@ -200,50 +200,50 @@ describe Mongoid::MoneyField do
|
|
200
200
|
|
201
201
|
it 'should have a Money value that matches the money value that was initially persisted' do
|
202
202
|
dummy = DummyMoney.first
|
203
|
-
dummy.price.cents.
|
203
|
+
expect(dummy.price.cents).to eq 123
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
207
|
describe 'when accessing a document from the datastore with a Money datatype and empty value' do
|
208
208
|
it 'should be nil' do
|
209
209
|
dummy = DummyMoneyWithoutDefault.new
|
210
|
-
dummy.save.
|
211
|
-
DummyMoneyWithoutDefault.first.price.
|
210
|
+
expect(dummy.save).to eq true
|
211
|
+
expect(DummyMoneyWithoutDefault.first.price).to be_nil
|
212
212
|
end
|
213
213
|
|
214
214
|
it 'should be 0 when used with default' do
|
215
215
|
dummy = DummyMoneyWithDefault.new
|
216
|
-
dummy.save.
|
217
|
-
DummyMoneyWithDefault.first.price.cents.
|
216
|
+
expect(dummy.save).to eq true
|
217
|
+
expect(DummyMoneyWithDefault.first.price.cents).to eq 100
|
218
218
|
end
|
219
219
|
|
220
220
|
it 'should set money to default currency if money is given without it' do
|
221
221
|
dummy = DummyMoneyWithDefault.new
|
222
|
-
dummy.save.
|
222
|
+
expect(dummy.save).to eq true
|
223
223
|
dummy = DummyMoneyWithDefault.first
|
224
|
-
dummy.price.currency.iso_code.
|
225
|
-
dummy.price.cents.
|
224
|
+
expect(dummy.price.currency.iso_code).to eq Money.default_currency.iso_code
|
225
|
+
expect(dummy.price.cents).to eq 100
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should set money to default currency if money is given without it on a document with multiple money fields' do
|
229
229
|
dummy = DummyPrices.new
|
230
|
-
dummy.save.
|
230
|
+
expect(dummy.save).to eq true
|
231
231
|
dummy = DummyPrices.first
|
232
|
-
dummy.price.currency.iso_code.
|
233
|
-
dummy.price.cents.
|
232
|
+
expect(dummy.price.currency.iso_code).to eq Money.default_currency.iso_code
|
233
|
+
expect(dummy.price.cents).to eq 100
|
234
234
|
|
235
|
-
dummy.price2.
|
235
|
+
expect(dummy.price2).to be_nil
|
236
236
|
|
237
|
-
dummy.price1.cents.
|
237
|
+
expect(dummy.price1.cents).to eq 0
|
238
238
|
end
|
239
239
|
|
240
240
|
|
241
241
|
it 'should set money to correct currency if money is given with it' do
|
242
242
|
dummy = DummyMoneyWithDefaultWithCurrency.new
|
243
|
-
dummy.save.
|
243
|
+
expect(dummy.save).to eq true
|
244
244
|
dummy = DummyMoneyWithDefaultWithCurrency.first
|
245
|
-
dummy.price.currency.iso_code.
|
246
|
-
dummy.price.cents.
|
245
|
+
expect(dummy.price.currency.iso_code).to eq 'GBP'
|
246
|
+
expect(dummy.price.cents).to eq 100
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
@@ -251,24 +251,24 @@ describe Mongoid::MoneyField do
|
|
251
251
|
it 'should have correct currency when value is set to 5$' do
|
252
252
|
DummyMoneyWithFixedCurrency.create!(price: '5$')
|
253
253
|
dummy = DummyMoneyWithFixedCurrency.first
|
254
|
-
dummy.price.currency.iso_code.
|
255
|
-
dummy.price.cents.
|
256
|
-
dummy.price.
|
254
|
+
expect(dummy.price.currency.iso_code).to eq 'GBP'
|
255
|
+
expect(dummy.price.cents).to eq 500
|
256
|
+
expect(dummy.price).to eq Monetize.parse('5 GBP')
|
257
257
|
end
|
258
258
|
|
259
259
|
it 'works for other field' do
|
260
260
|
DummyMoneyWithFixedCurrency.create!(old_price: '5$', price: '')
|
261
261
|
dummy = DummyMoneyWithFixedCurrency.first
|
262
|
-
dummy.price.
|
263
|
-
dummy.old_price.cents.
|
262
|
+
expect(dummy.price).to be_nil
|
263
|
+
expect(dummy.old_price.cents).to eq 500
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'should have correct currency when value is set to 100 RUB' do
|
267
267
|
DummyMoneyWithFixedCurrency.create!(price: '100 RUB')
|
268
268
|
dummy = DummyMoneyWithFixedCurrency.first
|
269
|
-
dummy.price.currency.iso_code.
|
270
|
-
dummy.price.cents.
|
271
|
-
dummy.price.
|
269
|
+
expect(dummy.price.currency.iso_code).to eq 'GBP'
|
270
|
+
expect(dummy.price.cents).to eq 100_00
|
271
|
+
expect(dummy.price).to eq Monetize.parse('100 GBP')
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -276,17 +276,17 @@ describe Mongoid::MoneyField do
|
|
276
276
|
it 'should handle RUB' do
|
277
277
|
DummyMoney.create(description: "Test", price: '1.23 RUB')
|
278
278
|
dummy = DummyMoney.first
|
279
|
-
dummy.price.currency.iso_code.
|
280
|
-
dummy.price.cents.
|
281
|
-
dummy.price.
|
279
|
+
expect(dummy.price.currency.iso_code).to eq 'RUB'
|
280
|
+
expect(dummy.price.cents).to eq 123
|
281
|
+
expect(dummy.price).to eq Monetize.parse('1.23 RUB')
|
282
282
|
end
|
283
283
|
|
284
284
|
it 'should handle $' do
|
285
285
|
DummyMoney.create(description: "Test", price: '1.23 USD')
|
286
286
|
dummy = DummyMoney.first
|
287
|
-
dummy.price.currency.iso_code.
|
288
|
-
dummy.price.cents.
|
289
|
-
dummy.price.
|
287
|
+
expect(dummy.price.currency.iso_code).to eq 'USD'
|
288
|
+
expect(dummy.price.cents).to eq 123
|
289
|
+
expect(dummy.price).to eq Monetize.parse('1.23 USD')
|
290
290
|
end
|
291
291
|
end
|
292
292
|
|
@@ -297,25 +297,25 @@ describe Mongoid::MoneyField do
|
|
297
297
|
|
298
298
|
it 'should be nil' do
|
299
299
|
dummy = DummyMoney.first
|
300
|
-
dummy.price.
|
300
|
+
expect(dummy.price).to be_nil
|
301
301
|
end
|
302
302
|
|
303
303
|
it 'stays nil' do
|
304
304
|
dummy = DummyMoney.first
|
305
305
|
dummy.price = ''
|
306
|
-
dummy.price.
|
307
|
-
dummy.save.
|
308
|
-
DummyMoney.first.price.
|
306
|
+
expect(dummy.price).to be_nil
|
307
|
+
expect(dummy.save).to be_truthy
|
308
|
+
expect(DummyMoney.first.price).to be_nil
|
309
309
|
end
|
310
310
|
|
311
311
|
it 'should be updated correctly' do
|
312
312
|
dummy = DummyMoney.first
|
313
|
-
dummy.price.
|
313
|
+
expect(dummy.price).to be_nil
|
314
314
|
dummy.price = '1.23 USD'
|
315
|
-
dummy.save.
|
315
|
+
expect(dummy.save).to eq true
|
316
316
|
dummy = DummyMoney.first
|
317
|
-
dummy.price.currency.iso_code.
|
318
|
-
dummy.price.cents.
|
317
|
+
expect(dummy.price.currency.iso_code).to eq 'USD'
|
318
|
+
expect(dummy.price.cents).to eq 123
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
@@ -332,12 +332,12 @@ describe Mongoid::MoneyField do
|
|
332
332
|
|
333
333
|
it 'should have correct value for first item' do
|
334
334
|
o = DummyOrder.first
|
335
|
-
o.dummy_line_items.first.price.
|
335
|
+
expect(o.dummy_line_items.first.price).to eq Monetize.parse('12.99')
|
336
336
|
end
|
337
337
|
|
338
338
|
it 'should have correct value for first item' do
|
339
339
|
o = DummyOrder.first
|
340
|
-
o.dummy_line_items.last.price.
|
340
|
+
expect(o.dummy_line_items.last.price).to eq Monetize.parse('14.99')
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
@@ -348,15 +348,15 @@ describe Mongoid::MoneyField do
|
|
348
348
|
|
349
349
|
it 'should have correct Money value for field 1' do
|
350
350
|
dummy = DummyPrices.first
|
351
|
-
dummy.price1.
|
351
|
+
expect(dummy.price1).to eq Monetize.parse('1.23')
|
352
352
|
end
|
353
353
|
it 'should have correct Money value for field 2' do
|
354
354
|
dummy = DummyPrices.first
|
355
|
-
dummy.price2.
|
355
|
+
expect(dummy.price2).to eq Monetize.parse('2.33')
|
356
356
|
end
|
357
357
|
it 'should have correct Money value for field 3' do
|
358
358
|
dummy = DummyPrices.first
|
359
|
-
dummy.price3.
|
359
|
+
expect(dummy.price3).to eq Monetize.parse('1')
|
360
360
|
end
|
361
361
|
end
|
362
362
|
end
|
data/spec/ruby_money_spec.rb
CHANGED
@@ -15,48 +15,48 @@ describe Money do
|
|
15
15
|
|
16
16
|
context "mongoize" do
|
17
17
|
it "mongoizes correctly a Money object to a hash of cents and currency" do
|
18
|
-
priceable.price.cents.
|
19
|
-
priceable.price.currency.
|
18
|
+
expect(priceable.price.cents).to eq(100)
|
19
|
+
expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
|
20
20
|
end
|
21
21
|
|
22
22
|
it "mongoizes correctly a Numeric object to a hash of cents and currency" do
|
23
|
-
priceable_from_num.price.cents.
|
24
|
-
priceable_from_num.price.currency.
|
23
|
+
expect(priceable_from_num.price.cents).to eq(100)
|
24
|
+
expect(priceable_from_num.price.currency).to eq(Money.default_currency)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "mongoizes correctly a String object to a hash of cents and currency" do
|
28
|
-
priceable_from_string.price.cents.
|
29
|
-
priceable_from_string.price.currency.
|
28
|
+
expect(priceable_from_string.price.cents).to eq(100)
|
29
|
+
expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
|
30
30
|
end
|
31
31
|
|
32
32
|
it "mongoizes correctly a hash of cents and currency" do
|
33
|
-
priceable_from_hash.price.cents.
|
34
|
-
priceable_from_hash.price.currency.
|
33
|
+
expect(priceable_from_hash.price.cents).to eq(100)
|
34
|
+
expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
|
35
35
|
end
|
36
36
|
|
37
37
|
it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
|
38
|
-
priceable_from_hash_with_indifferent_access.price.cents.
|
39
|
-
priceable_from_hash_with_indifferent_access.price.currency.
|
38
|
+
expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
|
39
|
+
expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
context "demongoize" do
|
44
44
|
subject { Priceable.first.price }
|
45
|
-
it {
|
46
|
-
it {
|
45
|
+
it { is_expected.to be_an_instance_of(Money) }
|
46
|
+
it { is_expected.to eq(Money.new(100, 'EUR')) }
|
47
47
|
it "returns nil if a nil value was stored" do
|
48
48
|
nil_priceable = Priceable.create(:price => nil)
|
49
|
-
nil_priceable.price.
|
49
|
+
expect(nil_priceable.price).to be_nil
|
50
50
|
end
|
51
51
|
it 'returns nil if an unknown value was stored' do
|
52
52
|
zero_priceable = Priceable.create(:price => [])
|
53
|
-
zero_priceable.price.
|
53
|
+
expect(zero_priceable.price).to be_nil
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
context "evolve" do
|
58
58
|
it "transforms correctly a Money object to a Mongo friendly value" do
|
59
|
-
Priceable.where(:price => Money.new(100, 'EUR')).first.
|
59
|
+
expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
metadata
CHANGED
@@ -1,153 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_money_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.2.
|
4
|
+
version: 5.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Tv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: money
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 6.1.0.beta1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 6.1.0.beta1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: monetize
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
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
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rdoc
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: database_cleaner
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: mongoid-rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
description: Use RubyMoney with mongoid
|
@@ -157,12 +157,12 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
-
- .document
|
161
|
-
- .gitignore
|
162
|
-
- .rspec
|
163
|
-
- .ruby-gemset
|
164
|
-
- .ruby-version
|
165
|
-
- .travis.yml
|
160
|
+
- ".document"
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
|
+
- ".ruby-gemset"
|
164
|
+
- ".ruby-version"
|
165
|
+
- ".travis.yml"
|
166
166
|
- Gemfile
|
167
167
|
- Gemfile.lock
|
168
168
|
- LICENSE.txt
|
@@ -205,17 +205,17 @@ require_paths:
|
|
205
205
|
- lib
|
206
206
|
required_ruby_version: !ruby/object:Gem::Requirement
|
207
207
|
requirements:
|
208
|
-
- -
|
208
|
+
- - ">="
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- -
|
213
|
+
- - ">="
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
217
|
rubyforge_project:
|
218
|
-
rubygems_version: 2.2.
|
218
|
+
rubygems_version: 2.2.2
|
219
219
|
signing_key:
|
220
220
|
specification_version: 4
|
221
221
|
summary: Use RubyMoney with mongoid
|