mongoid_money_field 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.document +0 -0
  3. data/.gitignore +0 -0
  4. data/.rspec +0 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +0 -0
  8. data/Gemfile +0 -0
  9. data/LICENSE.txt +0 -0
  10. data/README.rdoc +0 -0
  11. data/Rakefile +0 -0
  12. data/gemfiles/money4-mongoid3.gemfile +0 -0
  13. data/gemfiles/money4-mongoid31.gemfile +11 -11
  14. data/gemfiles/money50-mongoid3.gemfile +0 -0
  15. data/gemfiles/money50-mongoid31.gemfile +11 -11
  16. data/gemfiles/money51-mongoid3.gemfile +0 -0
  17. data/gemfiles/money51-mongoid31.gemfile +11 -11
  18. data/lib/mongoid_money_field.rb +3 -1
  19. data/lib/mongoid_money_field/field.rb +50 -48
  20. data/lib/mongoid_money_field/simple_form/money_input.rb +0 -0
  21. data/lib/mongoid_money_field/version.rb +1 -1
  22. data/mongoid_money_field.gemspec +8 -7
  23. data/spec/model_spec.rb +7 -7
  24. data/spec/money3_compat_spec.rb +122 -122
  25. data/spec/money3_spec.rb +15 -15
  26. data/spec/money_spec.rb +15 -15
  27. data/spec/ruby_money_spec.rb +61 -61
  28. data/spec/spec_helper.rb +0 -0
  29. data/spec/support/dummy_embedded.rb +0 -0
  30. data/spec/support/dummy_money.rb +0 -0
  31. data/spec/support/dummy_money_required.rb +0 -0
  32. data/spec/support/dummy_money_with_default.rb +0 -0
  33. data/spec/support/dummy_money_with_default_with_currency.rb +0 -0
  34. data/spec/support/dummy_money_with_fixed_currency.rb +0 -0
  35. data/spec/support/dummy_money_without_default.rb +0 -0
  36. data/spec/support/dummy_not_a_number.rb +0 -0
  37. data/spec/support/dummy_override_default_currency.rb +0 -0
  38. data/spec/support/dummy_positive_number.rb +0 -0
  39. data/spec/support/dummy_prices.rb +0 -0
  40. data/spec/support/dummy_with_default_currency.rb +0 -0
  41. data/spec/support/money3.rb +0 -0
  42. data/spec/support/mongoid.yml +0 -0
  43. data/spec/support/priceable.rb +0 -0
  44. metadata +55 -66
  45. data/.rvmrc +0 -1
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 648dca24a6555a49ba84d6b8b008e80025bb9d5a
4
+ data.tar.gz: 90bb2ba95a27ae871f7767750ba139f97c8e7623
5
+ SHA512:
6
+ metadata.gz: 50ec23241327e065e2e1ec88922bdd9c15c8986b99169c025101935feb0937a0f0631f92cdccdbf9b8c6315516c9d1fd5f80bdad53a45c2e1a18d77fb882489c
7
+ data.tar.gz: ccbe3ad7e69df98cccf1ae2809a56b9431be3e56258590d8bd94f371b6018f8203294ce2b661e5bbcf7bed02402c88f89f711a5198a91b41c20a4e8707dfc9c1
data/.document CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ moneyfield
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.rdoc CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
@@ -1,12 +1,12 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'mongoid', '~> 3.1.0'
4
- gem "money", "~> 4.0.2"
5
-
6
- gem "rake"
7
- gem "bundler", "~> 1.3.4"
8
- gem "rspec", "~> 2.13.0"
9
- gem "rdoc", "~> 4.0.1"
10
- gem "simplecov", "~> 0.7.1", require: false
11
- gem "database_cleaner", "~> 0.9.1"
1
+ source "http://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 3.1.0'
4
+ gem "money", "~> 4.0.2"
5
+
6
+ gem "rake"
7
+ gem "bundler", "~> 1.3.4"
8
+ gem "rspec", "~> 2.13.0"
9
+ gem "rdoc", "~> 4.0.1"
10
+ gem "simplecov", "~> 0.7.1", require: false
11
+ gem "database_cleaner", "~> 0.9.1"
12
12
  gem "mongoid-rspec"
File without changes
@@ -1,12 +1,12 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'mongoid', '~> 3.1.0'
4
- gem "money", "~> 5.0.0"
5
-
6
- gem "rake"
7
- gem "bundler", "~> 1.3.4"
8
- gem "rspec", "~> 2.13.0"
9
- gem "rdoc", "~> 4.0.1"
10
- gem "simplecov", "~> 0.7.1", require: false
11
- gem "database_cleaner", "~> 0.9.1"
1
+ source "http://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 3.1.0'
4
+ gem "money", "~> 5.0.0"
5
+
6
+ gem "rake"
7
+ gem "bundler", "~> 1.3.4"
8
+ gem "rspec", "~> 2.13.0"
9
+ gem "rdoc", "~> 4.0.1"
10
+ gem "simplecov", "~> 0.7.1", require: false
11
+ gem "database_cleaner", "~> 0.9.1"
12
12
  gem "mongoid-rspec"
File without changes
@@ -1,12 +1,12 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'mongoid', '~> 3.1.0'
4
- gem "money", "~> 5.1.1"
5
-
6
- gem "rake"
7
- gem "bundler", "~> 1.3.4"
8
- gem "rspec", "~> 2.13.0"
9
- gem "rdoc", "~> 4.0.1"
10
- gem "simplecov", "~> 0.7.1", require: false
11
- gem "database_cleaner", "~> 0.9.1"
1
+ source "http://rubygems.org"
2
+
3
+ gem 'mongoid', '~> 3.1.0'
4
+ gem "money", "~> 5.1.1"
5
+
6
+ gem "rake"
7
+ gem "bundler", "~> 1.3.4"
8
+ gem "rspec", "~> 2.13.0"
9
+ gem "rdoc", "~> 4.0.1"
10
+ gem "simplecov", "~> 0.7.1", require: false
11
+ gem "database_cleaner", "~> 0.9.1"
12
12
  gem "mongoid-rspec"
@@ -1,6 +1,8 @@
1
1
  #encoding: utf-8
2
2
 
3
3
  require "money"
4
+ require 'monetize'
5
+ require 'monetize/core_extensions'
4
6
  require "mongoid_money_field/version"
5
7
  require "mongoid_money_field/field"
6
8
 
@@ -38,7 +40,7 @@ module Mongoid
38
40
  default = nil
39
41
  name = name.to_s
40
42
  unless opts[:default].nil?
41
- default = Money.parse(opts[:default])
43
+ default = Monetize.parse(opts[:default])
42
44
  end
43
45
 
44
46
  field name, type: Money, default: default
@@ -1,48 +1,50 @@
1
- # coding: utf-8
2
-
3
- class Money
4
- # Converts an object of this instance into a database friendly value.
5
- def mongoize
6
- {
7
- :cents => cents,
8
- :currency_iso => currency.iso_code
9
- }
10
- end
11
-
12
- class << self
13
-
14
- # Get the object as it was stored in the database, and instantiate
15
- # this custom class from it.
16
- def demongoize(object)
17
- if object.is_a?(Hash)
18
- object = object.symbolize_keys
19
- object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil
20
- else
21
- nil
22
- end
23
- end
24
-
25
- # Takes any possible object and converts it to how it would be
26
- # stored in the database.
27
- def mongoize(object)
28
- case
29
- when object.is_a?(Money) then object.mongoize
30
- when object.is_a?(Hash) then
31
- object.symbolize_keys! if object.respond_to?(:symbolize_keys!)
32
- ::Money.new(object[:cents], object[:currency_iso]).mongoize
33
- when object.respond_to?(:to_money) then
34
- object.to_money.mongoize
35
- else object
36
- end
37
- end
38
-
39
- # Converts the object that was supplied to a criteria and converts it
40
- # into a database friendly form.
41
- def evolve(object)
42
- case object
43
- when Money then object.mongoize
44
- else object
45
- end
46
- end
47
- end
48
- end
1
+ # coding: utf-8
2
+
3
+ # from https://github.com/RubyMoney/money-rails/blob/master/lib/money-rails/mongoid/money.rb
4
+
5
+ class Money
6
+ # Converts an object of this instance into a database friendly value.
7
+ def mongoize
8
+ {
9
+ :cents => cents,
10
+ :currency_iso => currency.iso_code
11
+ }
12
+ end
13
+
14
+ class << self
15
+
16
+ # Get the object as it was stored in the database, and instantiate
17
+ # this custom class from it.
18
+ def demongoize(object)
19
+ if object.is_a?(Hash)
20
+ object = object.symbolize_keys
21
+ object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil
22
+ else
23
+ nil
24
+ end
25
+ end
26
+
27
+ # Takes any possible object and converts it to how it would be
28
+ # stored in the database.
29
+ def mongoize(object)
30
+ case
31
+ when object.is_a?(Money) then object.mongoize
32
+ when object.is_a?(Hash) then
33
+ object.symbolize_keys! if object.respond_to?(:symbolize_keys!)
34
+ ::Money.new(object[:cents], object[:currency_iso]).mongoize
35
+ when object.respond_to?(:to_money) then
36
+ object.to_money.mongoize
37
+ else object
38
+ end
39
+ end
40
+
41
+ # Converts the object that was supplied to a criteria and converts it
42
+ # into a database friendly form.
43
+ def evolve(object)
44
+ case object
45
+ when Money then object.mongoize
46
+ else object
47
+ end
48
+ end
49
+ end
50
+ end
File without changes
@@ -1,3 +1,3 @@
1
1
  module MongoidMoneyField
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
@@ -19,13 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "mongoid", ">= 3.0.0"
22
- spec.add_runtime_dependency "money", ">= 5.0.0"
22
+ spec.add_runtime_dependency "monetize"
23
+ spec.add_runtime_dependency "money", "~> 6.1.0.beta1"
23
24
 
24
25
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "bundler", "~> 1.3.4"
26
- spec.add_development_dependency "rspec", "~> 2.13.0"
27
- spec.add_development_dependency "rdoc", "~> 4.0.1"
28
- spec.add_development_dependency "simplecov", "~> 0.7.1"
29
- spec.add_development_dependency "database_cleaner", "~> 0.9.1"
30
- spec.add_development_dependency "mongoid-rspec", "~> 1.7.0"
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rdoc"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "database_cleaner"
31
+ spec.add_development_dependency "mongoid-rspec"
31
32
  end
data/spec/model_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe DummyMoney do
6
- it { should allow_mass_assignment_of(:description) }
7
- it { should allow_mass_assignment_of(:price) }
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe DummyMoney do
6
+ it { should allow_mass_assignment_of(:description) }
7
+ it { should allow_mass_assignment_of(:price) }
8
8
  end
@@ -1,123 +1,123 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Money3Compat do
6
- it { should allow_mass_assignment_of(:description) }
7
- it { should allow_mass_assignment_of(:price) }
8
-
9
- it 'correctly reads old fields data' do
10
- Money3.create!(price_currency: 'GBP', price_cents: '12000')
11
- Money3Compat.first.price.cents.should eq 12000
12
- Money3Compat.first.price.currency.iso_code.should eq 'GBP'
13
- end
14
-
15
- it 'correctly works after save' do
16
- Money3.create!(price_currency: 'GBP', price_cents: '12000')
17
- Money3Compat.first.save.should be_true
18
-
19
- Money3Compat.first.price.cents.should eq 12000
20
- Money3Compat.first.price.currency.iso_code.should eq 'GBP'
21
- end
22
-
23
- it 'correctly migrates data' do
24
- Money3.create!(price_currency: 'GBP', price_cents: '12000')
25
-
26
- Money3.first.read_attribute(:price_currency).should_not be_nil
27
- Money3.first.read_attribute(:price_cents).should_not be_nil
28
-
29
- Money3.first.read_attribute(:price_currency).should eq 'GBP'
30
- Money3.first.read_attribute(:price_cents).should eq 12000
31
-
32
- Money3Compat.migrate_from_money_field_3!(:price)
33
-
34
- Money3Compat.first.price.cents.should eq 12000
35
- Money3Compat.first.price.currency.iso_code.should eq 'GBP'
36
-
37
- Money3.first.read_attribute(:price_currency).should be_nil
38
- Money3.first.read_attribute(:price_cents).should be_nil
39
-
40
- Money3Compat.first.read_attribute(:price_currency).should be_nil
41
- Money3Compat.first.read_attribute(:price_cents).should be_nil
42
-
43
- f = Money3Compat.first
44
- f.price = '32.00 GBP'
45
- f.save.should be_true
46
-
47
- Money3Compat.first.price.cents.should eq 3200
48
- Money3Compat.first.price.currency.iso_code.should eq 'GBP'
49
- end
50
-
51
- describe 'with fixed currency' do
52
- it 'correctly reads old' do
53
- Money3.create!(price_with_fix_cents: '12000')
54
- Money3Compat.first.price_with_fix.cents.should eq 12000
55
- Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
56
- end
57
-
58
- it 'correctly works after save' do
59
- Money3.create!(price_with_fix_cents: '12000')
60
- Money3Compat.first.save.should be_true
61
- Money3Compat.first.price_with_fix.cents.should eq 12000
62
- Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
63
- end
64
-
65
- it 'correctly migrates data' do
66
- Money3.create!(price_with_fix_cents: '12000')
67
- Money3Compat.migrate_from_money_field_3!(:price_with_fix)
68
-
69
- Money3Compat.first.read_attribute(:price_with_fix_currency).should be_nil
70
- Money3Compat.first.read_attribute(:price_with_fix_cents).should be_nil
71
-
72
- Money3Compat.first.price_with_fix.cents.should eq 12000
73
- Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
74
- end
75
- end
76
-
77
- describe 'with no default' do
78
- it 'correctly reads old' do
79
- Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
80
- Money3Compat.first.price_no_default.cents.should eq 12000
81
- Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
82
- end
83
-
84
- it 'correctly works after save' do
85
- Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
86
- Money3Compat.first.save.should be_true
87
- Money3Compat.first.price_no_default.cents.should eq 12000
88
- Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
89
- end
90
-
91
- it 'correctly migrates data' do
92
- Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
93
- Money3Compat.migrate_from_money_field_3!(:price_no_default)
94
-
95
- Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
96
- Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
97
-
98
- Money3Compat.first.price_no_default.cents.should eq 12000
99
- Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
100
- end
101
-
102
- it 'correctly migrates data with no currency' do
103
- Money3.create!(price_no_default_cents: '12000')
104
- Money3Compat.migrate_from_money_field_3!(:price_no_default)
105
-
106
- Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
107
- Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
108
-
109
- Money3Compat.first.price_no_default.cents.should eq 12000
110
- Money3Compat.first.price_no_default.currency.iso_code.should eq 'RUB'
111
- end
112
-
113
- it 'correctly migrates data with no cents' do
114
- Money3.create!()
115
- Money3Compat.migrate_from_money_field_3!(:price_no_default)
116
-
117
- Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
118
- Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
119
-
120
- Money3Compat.first.price_no_default.should be_nil
121
- end
122
- end
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Money3Compat do
6
+ it { should allow_mass_assignment_of(:description) }
7
+ it { should allow_mass_assignment_of(:price) }
8
+
9
+ it 'correctly reads old fields data' do
10
+ Money3.create!(price_currency: 'GBP', price_cents: '12000')
11
+ Money3Compat.first.price.cents.should eq 12000
12
+ Money3Compat.first.price.currency.iso_code.should eq 'GBP'
13
+ end
14
+
15
+ it 'correctly works after save' do
16
+ Money3.create!(price_currency: 'GBP', price_cents: '12000')
17
+ Money3Compat.first.save.should be_true
18
+
19
+ Money3Compat.first.price.cents.should eq 12000
20
+ Money3Compat.first.price.currency.iso_code.should eq 'GBP'
21
+ end
22
+
23
+ it 'correctly migrates data' do
24
+ Money3.create!(price_currency: 'GBP', price_cents: '12000')
25
+
26
+ Money3.first.read_attribute(:price_currency).should_not be_nil
27
+ Money3.first.read_attribute(:price_cents).should_not be_nil
28
+
29
+ Money3.first.read_attribute(:price_currency).should eq 'GBP'
30
+ Money3.first.read_attribute(:price_cents).should eq 12000
31
+
32
+ Money3Compat.migrate_from_money_field_3!(:price)
33
+
34
+ Money3Compat.first.price.cents.should eq 12000
35
+ Money3Compat.first.price.currency.iso_code.should eq 'GBP'
36
+
37
+ Money3.first.read_attribute(:price_currency).should be_nil
38
+ Money3.first.read_attribute(:price_cents).should be_nil
39
+
40
+ Money3Compat.first.read_attribute(:price_currency).should be_nil
41
+ Money3Compat.first.read_attribute(:price_cents).should be_nil
42
+
43
+ f = Money3Compat.first
44
+ f.price = '32.00 GBP'
45
+ f.save.should be_true
46
+
47
+ Money3Compat.first.price.cents.should eq 3200
48
+ Money3Compat.first.price.currency.iso_code.should eq 'GBP'
49
+ end
50
+
51
+ describe 'with fixed currency' do
52
+ it 'correctly reads old' do
53
+ Money3.create!(price_with_fix_cents: '12000')
54
+ Money3Compat.first.price_with_fix.cents.should eq 12000
55
+ Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
56
+ end
57
+
58
+ it 'correctly works after save' do
59
+ Money3.create!(price_with_fix_cents: '12000')
60
+ Money3Compat.first.save.should be_true
61
+ Money3Compat.first.price_with_fix.cents.should eq 12000
62
+ Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
63
+ end
64
+
65
+ it 'correctly migrates data' do
66
+ Money3.create!(price_with_fix_cents: '12000')
67
+ Money3Compat.migrate_from_money_field_3!(:price_with_fix)
68
+
69
+ Money3Compat.first.read_attribute(:price_with_fix_currency).should be_nil
70
+ Money3Compat.first.read_attribute(:price_with_fix_cents).should be_nil
71
+
72
+ Money3Compat.first.price_with_fix.cents.should eq 12000
73
+ Money3Compat.first.price_with_fix.currency.iso_code.should eq 'GBP'
74
+ end
75
+ end
76
+
77
+ describe 'with no default' do
78
+ it 'correctly reads old' do
79
+ Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
80
+ Money3Compat.first.price_no_default.cents.should eq 12000
81
+ Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
82
+ end
83
+
84
+ it 'correctly works after save' do
85
+ Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
86
+ Money3Compat.first.save.should be_true
87
+ Money3Compat.first.price_no_default.cents.should eq 12000
88
+ Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
89
+ end
90
+
91
+ it 'correctly migrates data' do
92
+ Money3.create!(price_no_default_currency: 'GBP', price_no_default_cents: '12000')
93
+ Money3Compat.migrate_from_money_field_3!(:price_no_default)
94
+
95
+ Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
96
+ Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
97
+
98
+ Money3Compat.first.price_no_default.cents.should eq 12000
99
+ Money3Compat.first.price_no_default.currency.iso_code.should eq 'GBP'
100
+ end
101
+
102
+ it 'correctly migrates data with no currency' do
103
+ Money3.create!(price_no_default_cents: '12000')
104
+ Money3Compat.migrate_from_money_field_3!(:price_no_default)
105
+
106
+ Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
107
+ Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
108
+
109
+ Money3Compat.first.price_no_default.cents.should eq 12000
110
+ Money3Compat.first.price_no_default.currency.iso_code.should eq 'RUB'
111
+ end
112
+
113
+ it 'correctly migrates data with no cents' do
114
+ Money3.create!()
115
+ Money3Compat.migrate_from_money_field_3!(:price_no_default)
116
+
117
+ Money3Compat.first.read_attribute(:price_no_default_currency).should be_nil
118
+ Money3Compat.first.read_attribute(:price_no_default_cents).should be_nil
119
+
120
+ Money3Compat.first.price_no_default.should be_nil
121
+ end
122
+ end
123
123
  end
data/spec/money3_spec.rb CHANGED
@@ -146,17 +146,17 @@ describe Mongoid::MoneyField do
146
146
 
147
147
  it 'should be persisted normally when set as Money' do
148
148
  dummy = DummyMoney.new
149
- dummy.price = Money.parse(1.23)
149
+ dummy.price = Monetize.parse(1.23)
150
150
  dummy.save.should eq true
151
151
  end
152
152
 
153
153
  it 'should be possible to set value to nil' do
154
154
  dummy = DummyMoney.new
155
- dummy.price = Money.parse(1.23)
155
+ dummy.price = Monetize.parse(1.23)
156
156
  dummy.save.should eq true
157
157
 
158
158
  dummy = DummyMoney.first
159
- dummy.price.should eq Money.parse(1.23)
159
+ dummy.price.should eq Monetize.parse(1.23)
160
160
  dummy.price = nil
161
161
  dummy.save.should eq true
162
162
  dummy = DummyMoney.first
@@ -171,14 +171,14 @@ describe Mongoid::MoneyField do
171
171
 
172
172
  it 'should have a Money value that matches the money value that was initially persisted' do
173
173
  dummy = DummyMoney.first
174
- dummy.price.should eq Money.parse('9.99')
174
+ dummy.price.should eq Monetize.parse('9.99')
175
175
  end
176
176
  end
177
177
 
178
178
  describe 'when accessing a document from the datastore with a Money datatype set as money' do
179
179
  before(:each) do
180
180
  dm = DummyMoney.create(:description => "Test")
181
- dm.price = Money.parse('1.23')
181
+ dm.price = Monetize.parse('1.23')
182
182
  dm.save!
183
183
  end
184
184
 
@@ -190,7 +190,7 @@ describe Mongoid::MoneyField do
190
190
 
191
191
  describe 'when accessing a document from the datastore with a Money datatype set as money with mass asignment' do
192
192
  before(:each) do
193
- DummyMoney.create(:description => "Test", :price => Money.parse('1.23'))
193
+ DummyMoney.create(:description => "Test", :price => Monetize.parse('1.23'))
194
194
  end
195
195
 
196
196
  it 'should have a Money value that matches the money value that was initially persisted' do
@@ -248,7 +248,7 @@ describe Mongoid::MoneyField do
248
248
  dummy = DummyMoneyWithFixedCurrency.first
249
249
  dummy.price.currency.iso_code.should eq 'GBP'
250
250
  dummy.price.cents.should eq 500
251
- dummy.price.should eq Money.parse('5 GBP')
251
+ dummy.price.should eq Monetize.parse('5 GBP')
252
252
  end
253
253
 
254
254
  it 'should have correct currency when value is set to 100 RUB' do
@@ -256,7 +256,7 @@ describe Mongoid::MoneyField do
256
256
  dummy = DummyMoneyWithFixedCurrency.first
257
257
  dummy.price.currency.iso_code.should eq 'GBP'
258
258
  dummy.price.cents.should eq 100_00
259
- dummy.price.should eq Money.parse('100 GBP')
259
+ dummy.price.should eq Monetize.parse('100 GBP')
260
260
  end
261
261
  end
262
262
 
@@ -266,7 +266,7 @@ describe Mongoid::MoneyField do
266
266
  dummy = DummyMoney.first
267
267
  dummy.price.currency.iso_code.should eq 'RUB'
268
268
  dummy.price.cents.should eq 123
269
- dummy.price.should eq Money.parse('1.23 RUB')
269
+ dummy.price.should eq Monetize.parse('1.23 RUB')
270
270
  end
271
271
 
272
272
  it 'should handle $' do
@@ -274,7 +274,7 @@ describe Mongoid::MoneyField do
274
274
  dummy = DummyMoney.first
275
275
  dummy.price.currency.iso_code.should eq 'USD'
276
276
  dummy.price.cents.should eq 123
277
- dummy.price.should eq Money.parse('1.23 USD')
277
+ dummy.price.should eq Monetize.parse('1.23 USD')
278
278
  end
279
279
  end
280
280
 
@@ -312,12 +312,12 @@ describe Mongoid::MoneyField do
312
312
 
313
313
  it 'should have correct value for first item' do
314
314
  o = DummyOrder.first
315
- o.dummy_line_items.first.price.should eq Money.parse('12.99')
315
+ o.dummy_line_items.first.price.should eq Monetize.parse('12.99')
316
316
  end
317
317
 
318
318
  it 'should have correct value for first item' do
319
319
  o = DummyOrder.first
320
- o.dummy_line_items.last.price.should eq Money.parse('14.99')
320
+ o.dummy_line_items.last.price.should eq Monetize.parse('14.99')
321
321
  end
322
322
  end
323
323
 
@@ -328,15 +328,15 @@ describe Mongoid::MoneyField do
328
328
 
329
329
  it 'should have correct Money value for field 1' do
330
330
  dummy = DummyPrices.first
331
- dummy.price1.should eq Money.parse('1.23')
331
+ dummy.price1.should eq Monetize.parse('1.23')
332
332
  end
333
333
  it 'should have correct Money value for field 2' do
334
334
  dummy = DummyPrices.first
335
- dummy.price2.should eq Money.parse('2.33')
335
+ dummy.price2.should eq Monetize.parse('2.33')
336
336
  end
337
337
  it 'should have correct Money value for field 3' do
338
338
  dummy = DummyPrices.first
339
- dummy.price3.should eq Money.parse('1')
339
+ dummy.price3.should eq Monetize.parse('1')
340
340
  end
341
341
  end
342
342
  end
data/spec/money_spec.rb CHANGED
@@ -152,17 +152,17 @@ describe Mongoid::MoneyField do
152
152
 
153
153
  it 'should be persisted normally when set as Money' do
154
154
  dummy = DummyMoney.new
155
- dummy.price = Money.parse(1.23)
155
+ dummy.price = Monetize.parse(1.23)
156
156
  dummy.save.should eq true
157
157
  end
158
158
 
159
159
  it 'should be possible to set value to nil' do
160
160
  dummy = DummyMoney.new
161
- dummy.price = Money.parse(1.23)
161
+ dummy.price = Monetize.parse(1.23)
162
162
  dummy.save.should eq true
163
163
 
164
164
  dummy = DummyMoney.first
165
- dummy.price.should eq Money.parse(1.23)
165
+ dummy.price.should eq Monetize.parse(1.23)
166
166
  dummy.price = nil
167
167
  dummy.save.should eq true
168
168
  dummy = DummyMoney.first
@@ -177,14 +177,14 @@ describe Mongoid::MoneyField do
177
177
 
178
178
  it 'should have a Money value that matches the money value that was initially persisted' do
179
179
  dummy = DummyMoney.first
180
- dummy.price.should eq Money.parse('9.99')
180
+ dummy.price.should eq Monetize.parse('9.99')
181
181
  end
182
182
  end
183
183
 
184
184
  describe 'when accessing a document from the datastore with a Money datatype set as money' do
185
185
  before(:each) do
186
186
  dm = DummyMoney.create(:description => "Test")
187
- dm.price = Money.parse('1.23')
187
+ dm.price = Monetize.parse('1.23')
188
188
  dm.save!
189
189
  end
190
190
 
@@ -196,7 +196,7 @@ describe Mongoid::MoneyField do
196
196
 
197
197
  describe 'when accessing a document from the datastore with a Money datatype set as money with mass asignment' do
198
198
  before(:each) do
199
- DummyMoney.create(:description => "Test", :price => Money.parse('1.23'))
199
+ DummyMoney.create(:description => "Test", :price => Monetize.parse('1.23'))
200
200
  end
201
201
 
202
202
  it 'should have a Money value that matches the money value that was initially persisted' do
@@ -254,7 +254,7 @@ describe Mongoid::MoneyField do
254
254
  dummy = DummyMoneyWithFixedCurrency.first
255
255
  dummy.price.currency.iso_code.should eq 'GBP'
256
256
  dummy.price.cents.should eq 500
257
- dummy.price.should eq Money.parse('5 GBP')
257
+ dummy.price.should eq Monetize.parse('5 GBP')
258
258
  end
259
259
 
260
260
  it 'should have correct currency when value is set to 100 RUB' do
@@ -262,7 +262,7 @@ describe Mongoid::MoneyField do
262
262
  dummy = DummyMoneyWithFixedCurrency.first
263
263
  dummy.price.currency.iso_code.should eq 'GBP'
264
264
  dummy.price.cents.should eq 100_00
265
- dummy.price.should eq Money.parse('100 GBP')
265
+ dummy.price.should eq Monetize.parse('100 GBP')
266
266
  end
267
267
  end
268
268
 
@@ -272,7 +272,7 @@ describe Mongoid::MoneyField do
272
272
  dummy = DummyMoney.first
273
273
  dummy.price.currency.iso_code.should eq 'RUB'
274
274
  dummy.price.cents.should eq 123
275
- dummy.price.should eq Money.parse('1.23 RUB')
275
+ dummy.price.should eq Monetize.parse('1.23 RUB')
276
276
  end
277
277
 
278
278
  it 'should handle $' do
@@ -280,7 +280,7 @@ describe Mongoid::MoneyField do
280
280
  dummy = DummyMoney.first
281
281
  dummy.price.currency.iso_code.should eq 'USD'
282
282
  dummy.price.cents.should eq 123
283
- dummy.price.should eq Money.parse('1.23 USD')
283
+ dummy.price.should eq Monetize.parse('1.23 USD')
284
284
  end
285
285
  end
286
286
 
@@ -326,12 +326,12 @@ describe Mongoid::MoneyField do
326
326
 
327
327
  it 'should have correct value for first item' do
328
328
  o = DummyOrder.first
329
- o.dummy_line_items.first.price.should eq Money.parse('12.99')
329
+ o.dummy_line_items.first.price.should eq Monetize.parse('12.99')
330
330
  end
331
331
 
332
332
  it 'should have correct value for first item' do
333
333
  o = DummyOrder.first
334
- o.dummy_line_items.last.price.should eq Money.parse('14.99')
334
+ o.dummy_line_items.last.price.should eq Monetize.parse('14.99')
335
335
  end
336
336
  end
337
337
 
@@ -342,15 +342,15 @@ describe Mongoid::MoneyField do
342
342
 
343
343
  it 'should have correct Money value for field 1' do
344
344
  dummy = DummyPrices.first
345
- dummy.price1.should eq Money.parse('1.23')
345
+ dummy.price1.should eq Monetize.parse('1.23')
346
346
  end
347
347
  it 'should have correct Money value for field 2' do
348
348
  dummy = DummyPrices.first
349
- dummy.price2.should eq Money.parse('2.33')
349
+ dummy.price2.should eq Monetize.parse('2.33')
350
350
  end
351
351
  it 'should have correct Money value for field 3' do
352
352
  dummy = DummyPrices.first
353
- dummy.price3.should eq Money.parse('1')
353
+ dummy.price3.should eq Monetize.parse('1')
354
354
  end
355
355
  end
356
356
  end
@@ -1,62 +1,62 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- # from https://github.com/RubyMoney/money-rails/blob/master/spec/mongoid/three_spec.rb
6
-
7
- describe Money do
8
- let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
9
- let!(:priceable_from_num) { Priceable.create(:price => 1) }
10
- let!(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
11
- let!(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
12
- let!(:priceable_from_hash_with_indifferent_access) {
13
- Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
14
- }
15
-
16
- context "mongoize" do
17
- it "mongoizes correctly a Money object to a hash of cents and currency" do
18
- priceable.price.cents.should == 100
19
- priceable.price.currency.should == Money::Currency.find('EUR')
20
- end
21
-
22
- it "mongoizes correctly a Numeric object to a hash of cents and currency" do
23
- priceable_from_num.price.cents.should == 100
24
- priceable_from_num.price.currency.should == Money.default_currency
25
- end
26
-
27
- it "mongoizes correctly a String object to a hash of cents and currency" do
28
- priceable_from_string.price.cents.should == 100
29
- priceable_from_string.price.currency.should == Money::Currency.find('EUR')
30
- end
31
-
32
- it "mongoizes correctly a hash of cents and currency" do
33
- priceable_from_hash.price.cents.should == 100
34
- priceable_from_hash.price.currency.should == Money::Currency.find('EUR')
35
- end
36
-
37
- it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
38
- priceable_from_hash_with_indifferent_access.price.cents.should == 100
39
- priceable_from_hash_with_indifferent_access.price.currency.should == Money::Currency.find('EUR')
40
- end
41
- end
42
-
43
- context "demongoize" do
44
- subject { Priceable.first.price }
45
- it { should be_an_instance_of(Money) }
46
- it { should == Money.new(100, 'EUR') }
47
- it "returns nil if a nil value was stored" do
48
- nil_priceable = Priceable.create(:price => nil)
49
- nil_priceable.price.should be_nil
50
- end
51
- it 'returns nil if an unknown value was stored' do
52
- zero_priceable = Priceable.create(:price => [])
53
- zero_priceable.price.should be_nil
54
- end
55
- end
56
-
57
- context "evolve" do
58
- it "transforms correctly a Money object to a Mongo friendly value" do
59
- Priceable.where(:price => Money.new(100, 'EUR')).first.should == priceable
60
- end
61
- end
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ # from https://github.com/RubyMoney/money-rails/blob/master/spec/mongoid/three_spec.rb
6
+
7
+ describe Money do
8
+ let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
9
+ let!(:priceable_from_num) { Priceable.create(:price => 1) }
10
+ let!(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
11
+ let!(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
12
+ let!(:priceable_from_hash_with_indifferent_access) {
13
+ Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
14
+ }
15
+
16
+ context "mongoize" do
17
+ it "mongoizes correctly a Money object to a hash of cents and currency" do
18
+ priceable.price.cents.should == 100
19
+ priceable.price.currency.should == Money::Currency.find('EUR')
20
+ end
21
+
22
+ it "mongoizes correctly a Numeric object to a hash of cents and currency" do
23
+ priceable_from_num.price.cents.should == 100
24
+ priceable_from_num.price.currency.should == Money.default_currency
25
+ end
26
+
27
+ it "mongoizes correctly a String object to a hash of cents and currency" do
28
+ priceable_from_string.price.cents.should == 100
29
+ priceable_from_string.price.currency.should == Money::Currency.find('EUR')
30
+ end
31
+
32
+ it "mongoizes correctly a hash of cents and currency" do
33
+ priceable_from_hash.price.cents.should == 100
34
+ priceable_from_hash.price.currency.should == Money::Currency.find('EUR')
35
+ end
36
+
37
+ it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
38
+ priceable_from_hash_with_indifferent_access.price.cents.should == 100
39
+ priceable_from_hash_with_indifferent_access.price.currency.should == Money::Currency.find('EUR')
40
+ end
41
+ end
42
+
43
+ context "demongoize" do
44
+ subject { Priceable.first.price }
45
+ it { should be_an_instance_of(Money) }
46
+ it { should == Money.new(100, 'EUR') }
47
+ it "returns nil if a nil value was stored" do
48
+ nil_priceable = Priceable.create(:price => nil)
49
+ nil_priceable.price.should be_nil
50
+ end
51
+ it 'returns nil if an unknown value was stored' do
52
+ zero_priceable = Priceable.create(:price => [])
53
+ zero_priceable.price.should be_nil
54
+ end
55
+ end
56
+
57
+ context "evolve" do
58
+ it "transforms correctly a Money object to a Mongo friendly value" do
59
+ Priceable.where(:price => Money.new(100, 'EUR')).first.should == priceable
60
+ end
61
+ end
62
62
  end
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,160 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_money_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
5
- prerelease:
4
+ version: 4.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gleb Tv
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mongoid
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: monetize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: money
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ~>
36
46
  - !ruby/object:Gem::Version
37
- version: 5.0.0
47
+ version: 6.1.0.beta1
38
48
  type: :runtime
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ~>
44
53
  - !ruby/object:Gem::Version
45
- version: 5.0.0
54
+ version: 6.1.0.beta1
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: rake
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - '>='
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: bundler
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ~>
73
+ - - '>='
68
74
  - !ruby/object:Gem::Version
69
- version: 1.3.4
75
+ version: '0'
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ~>
80
+ - - '>='
76
81
  - !ruby/object:Gem::Version
77
- version: 1.3.4
82
+ version: '0'
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: rspec
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ~>
87
+ - - '>='
84
88
  - !ruby/object:Gem::Version
85
- version: 2.13.0
89
+ version: '0'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ~>
94
+ - - '>='
92
95
  - !ruby/object:Gem::Version
93
- version: 2.13.0
96
+ version: '0'
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: rdoc
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ~>
101
+ - - '>='
100
102
  - !ruby/object:Gem::Version
101
- version: 4.0.1
103
+ version: '0'
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ~>
108
+ - - '>='
108
109
  - !ruby/object:Gem::Version
109
- version: 4.0.1
110
+ version: '0'
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: simplecov
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
- - - ~>
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.7.1
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
- - - ~>
122
+ - - '>='
124
123
  - !ruby/object:Gem::Version
125
- version: 0.7.1
124
+ version: '0'
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: database_cleaner
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
- - - ~>
129
+ - - '>='
132
130
  - !ruby/object:Gem::Version
133
- version: 0.9.1
131
+ version: '0'
134
132
  type: :development
135
133
  prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
- - - ~>
136
+ - - '>='
140
137
  - !ruby/object:Gem::Version
141
- version: 0.9.1
138
+ version: '0'
142
139
  - !ruby/object:Gem::Dependency
143
140
  name: mongoid-rspec
144
141
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
142
  requirements:
147
- - - ~>
143
+ - - '>='
148
144
  - !ruby/object:Gem::Version
149
- version: 1.7.0
145
+ version: '0'
150
146
  type: :development
151
147
  prerelease: false
152
148
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
149
  requirements:
155
- - - ~>
150
+ - - '>='
156
151
  - !ruby/object:Gem::Version
157
- version: 1.7.0
152
+ version: '0'
158
153
  description: Use RubyMoney with mongoid
159
154
  email:
160
155
  - glebtv@gmail.com
@@ -165,7 +160,8 @@ files:
165
160
  - .document
166
161
  - .gitignore
167
162
  - .rspec
168
- - .rvmrc
163
+ - .ruby-gemset
164
+ - .ruby-version
169
165
  - .travis.yml
170
166
  - Gemfile
171
167
  - Gemfile.lock
@@ -207,33 +203,26 @@ files:
207
203
  homepage: http://github.com/glebtv/mongoid_money_field
208
204
  licenses:
209
205
  - MIT
206
+ metadata: {}
210
207
  post_install_message:
211
208
  rdoc_options: []
212
209
  require_paths:
213
210
  - lib
214
211
  required_ruby_version: !ruby/object:Gem::Requirement
215
- none: false
216
212
  requirements:
217
- - - ! '>='
213
+ - - '>='
218
214
  - !ruby/object:Gem::Version
219
215
  version: '0'
220
- segments:
221
- - 0
222
- hash: -1051362847442743993
223
216
  required_rubygems_version: !ruby/object:Gem::Requirement
224
- none: false
225
217
  requirements:
226
- - - ! '>='
218
+ - - '>='
227
219
  - !ruby/object:Gem::Version
228
220
  version: '0'
229
- segments:
230
- - 0
231
- hash: -1051362847442743993
232
221
  requirements: []
233
222
  rubyforge_project:
234
- rubygems_version: 1.8.25
223
+ rubygems_version: 2.2.1
235
224
  signing_key:
236
- specification_version: 3
225
+ specification_version: 4
237
226
  summary: Use RubyMoney with mongoid
238
227
  test_files:
239
228
  - spec/model_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3@moneyfield --create