has_money_fields 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +11 -0
- data/README.md +2 -0
- data/lib/has_money_fields.rb +4 -6
- data/lib/has_money_fields/version.rb +1 -1
- data/spec/has_money_fields_spec.rb +25 -0
- data/spec/models.rb +1 -1
- metadata +5 -4
data/History.md
ADDED
data/README.md
CHANGED
data/lib/has_money_fields.rb
CHANGED
@@ -9,10 +9,6 @@ module HasMoneyFields
|
|
9
9
|
options.assert_valid_keys(:only_cents)
|
10
10
|
|
11
11
|
args.each do |attr|
|
12
|
-
constructor = Proc.new do |cents, currency|
|
13
|
-
Money.new(cents || 0, currency || Money.default_currency)
|
14
|
-
end
|
15
|
-
|
16
12
|
converter = Proc.new do |value|
|
17
13
|
if value.respond_to? :to_money
|
18
14
|
value.to_money
|
@@ -30,8 +26,10 @@ module HasMoneyFields
|
|
30
26
|
self.composed_of attr,
|
31
27
|
:class_name => "Money",
|
32
28
|
:mapping => mapping,
|
33
|
-
:constructor =>
|
34
|
-
:converter => converter
|
29
|
+
:constructor => :new,
|
30
|
+
:converter => converter,
|
31
|
+
:allow_nil => true
|
32
|
+
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -27,4 +27,29 @@ describe "Model with money fields" do
|
|
27
27
|
its(:money_price_in_usd) { should == 1000 }
|
28
28
|
its(:price_in_usd) { should == Money.new(1000, "USD") }
|
29
29
|
end
|
30
|
+
|
31
|
+
context "with a nil values" do
|
32
|
+
before do
|
33
|
+
@product = Product.create! :price => nil, :price_in_usd => nil
|
34
|
+
end
|
35
|
+
subject {@product}
|
36
|
+
|
37
|
+
its(:money_price){ should be_nil }
|
38
|
+
its(:currency_price){ should be_nil }
|
39
|
+
its(:money_price_in_usd) { should be_nil }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with validations" do
|
43
|
+
before do
|
44
|
+
Product.class_eval do
|
45
|
+
validates :price, :presence => true
|
46
|
+
end
|
47
|
+
|
48
|
+
@product = Product.new :price => nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "is invalid" do
|
52
|
+
@product.save.should be_false
|
53
|
+
end
|
54
|
+
end
|
30
55
|
end
|
data/spec/models.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_money_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Francisco J. Casas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-14 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- .gitignore
|
134
134
|
- Gemfile
|
135
135
|
- Guardfile
|
136
|
+
- History.md
|
136
137
|
- LICENSE
|
137
138
|
- README.md
|
138
139
|
- Rakefile
|