mongoid_money_field 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -11,14 +11,6 @@ A simple gem that creates a Money datatype using RubyMoney for Mongoid.
11
11
 
12
12
  Inspired by https://gist.github.com/840500
13
13
 
14
- == Updating
15
-
16
- v2.0 breaks compatibility as it does not give 0 cents default anymore. Use
17
-
18
- money_field_with_options :price, default: 0
19
-
20
- instead
21
-
22
14
  == Installation
23
15
 
24
16
  Include the gem in your Gemfile
@@ -33,7 +25,8 @@ Include the gem in your Gemfile
33
25
 
34
26
  field :description
35
27
 
36
- money_field :price, :old_price
28
+ money_field :cart_total # defaults to 0
29
+ money_field_without_default :price, :old_price # defaults to nil
37
30
 
38
31
  # to disallow changing currency (and to not store it in database)
39
32
  money_field_with_options :price2, fixed_currency: 'GBP'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0
@@ -66,6 +66,10 @@ module Mongoid
66
66
  end
67
67
 
68
68
  def money_field(*columns)
69
+ money_field_with_options(columns, default: 0)
70
+ end
71
+
72
+ def money_field_without_default(*columns)
69
73
  money_field_with_options(columns)
70
74
  end
71
75
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mongoid_money_field"
8
- s.version = "2.0.1"
8
+ s.version = "2.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["glebtv"]
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "spec/support/dummy_money_with_default.rb",
36
36
  "spec/support/dummy_money_with_default_with_currency.rb",
37
37
  "spec/support/dummy_money_with_fixed_currency.rb",
38
+ "spec/support/dummy_money_without_default.rb",
38
39
  "spec/support/dummy_prices.rb"
39
40
  ]
40
41
  s.homepage = "http://github.com/glebtv/mongoid_money_field"
data/spec/money_spec.rb CHANGED
@@ -73,9 +73,15 @@ describe Mongoid::MoneyField do
73
73
 
74
74
  describe 'when accessing a document from the datastore with a Money datatype and empty value' do
75
75
  it 'should be nil' do
76
+ dummy = DummyMoneyWithoutDefault.new
77
+ dummy.save.should eq true
78
+ DummyMoneyWithoutDefault.first.price.should be_nil
79
+ end
80
+
81
+ it 'should be 0 when used with default' do
76
82
  dummy = DummyMoney.new
77
83
  dummy.save.should eq true
78
- DummyMoney.first.price.should be_nil
84
+ DummyMoney.first.price.cents.should eq 0
79
85
  end
80
86
 
81
87
  it 'should set money to default currency if money is given without it' do
@@ -92,8 +98,10 @@ describe Mongoid::MoneyField do
92
98
  dummy = DummyPrices.first
93
99
  dummy.price.currency.iso_code.should eq Money.default_currency.iso_code
94
100
  dummy.price.cents.should eq 100
101
+
102
+ dummy.price_nodef.should be_nil
95
103
 
96
- dummy.price1.should be_nil
104
+ dummy.price1.cents.should eq 0
97
105
  end
98
106
 
99
107
 
@@ -0,0 +1,9 @@
1
+ class DummyMoneyWithoutDefault
2
+ include Mongoid::Document
3
+ include Mongoid::MoneyField
4
+
5
+ field :description
6
+
7
+ money_field_without_default :price
8
+
9
+ end
@@ -7,4 +7,6 @@ class DummyPrices
7
7
  money_field :price1, :price2, :price3
8
8
 
9
9
  money_field_with_options :price, default: 1.00
10
+
11
+ money_field_without_default :price_nodef
10
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_money_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -165,6 +165,7 @@ files:
165
165
  - spec/support/dummy_money_with_default.rb
166
166
  - spec/support/dummy_money_with_default_with_currency.rb
167
167
  - spec/support/dummy_money_with_fixed_currency.rb
168
+ - spec/support/dummy_money_without_default.rb
168
169
  - spec/support/dummy_prices.rb
169
170
  homepage: http://github.com/glebtv/mongoid_money_field
170
171
  licenses:
@@ -181,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  segments:
183
184
  - 0
184
- hash: 1059857057601386620
185
+ hash: -1966677237532462947
185
186
  required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  none: false
187
188
  requirements: