<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -8,16 +8,24 @@ module ActiveRecord #:nodoc:
       end
 
       module ClassMethods
-        
         def money(name, options = {})
+          allow_nil = options.has_key?(:allow_nil) ? options.delete(:allow_nil) : true
           options = {:precision =&gt; 2, :cents =&gt; &quot;#{name}_in_cents&quot;.to_sym }.merge(options)
           mapping = [[options[:cents], 'cents']]
           mapping &lt;&lt; [options[:currency].to_s, 'currency'] if options[:currency]
-          composed_of name, :class_name =&gt; 'Money', :mapping =&gt; mapping, :allow_nil =&gt; true,
-            :converter =&gt; lambda{ |m| m.to_money(options[:precision]) },
+          composed_of name, :class_name =&gt; 'Money', :mapping =&gt; mapping, :allow_nil =&gt; allow_nil,
+            :converter =&gt; lambda{ |m|
+              if !allow_nil &amp;&amp; m.nil?
+                currency = options[:currency] || ::Money.default_currency
+                m = ::Money.new(0, currency, options[:precision])
+              end
+              m.to_money(options[:precision])
+            },
             :constructor =&gt; lambda{ |*args| 
               cents, currency = args
-              ::Money.new(cents, (currency || ::Money.default_currency), options[:precision]) 
+              cents ||= 0
+              currency ||= ::Money.default_currency
+              ::Money.new(cents, currency, options[:precision]) 
             }
 
           define_method &quot;#{name}_with_cleanup=&quot; do |amount|</diff>
      <filename>lib/money/rails.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,6 +23,13 @@ class OtherMoneyExample &lt; ActiveRecord::Base
   money :precise_amount, :cents =&gt; &quot;credit_amount_in_cents&quot;, :precision =&gt; 3
 end
 
+class YetAnotherMoneyExample &lt; ActiveRecord::Base
+  set_table_name &quot;money_examples&quot;
+  
+  money :amount, :allow_nil =&gt; false
+  money :precise_amount, :allow_nil =&gt; false, :precision =&gt; 3
+end
+
 describe Money, &quot;using the money declaration in an ActiveRecord model&quot; do
   it &quot;should allow dynamic finders to work the same as composed_of&quot; do
     record = MoneyExample.create!(:debit_amount =&gt; 100.to_money)
@@ -75,6 +82,19 @@ describe Money, &quot;using the money declaration in an ActiveRecord model&quot; do
       ome = OtherMoneyExample.new(:credit_amount_in_cents =&gt; 535)
       ome.precise_amount.should == Money.new(535, 'USD', 3)
     end
-
+  end
+  
+  describe &quot;defaulting to $0&quot; do
+    context &quot;when the amount is nil&quot; do
+      it &quot;should default to $0&quot; do
+        YetAnotherMoneyExample.new(:amount =&gt; nil).amount.should == Money.new(0, 'USD', 2)
+      end
+    end
+    
+    context &quot;when the precision is configured&quot; do
+      it &quot;should default to $0 with the right precision&quot; do
+        YetAnotherMoneyExample.new(:precise_amount =&gt; nil).amount.should == Money.new(0, 'USD', 3)
+      end
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>spec/money/rails/rails_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>37f5d4b3cfaba04569147af14bb41a2cd6996aa7</id>
    </parent>
  </parents>
  <author>
    <name>Zach Dennis</name>
    <email>zach.dennis@gmail.com</email>
  </author>
  <url>http://github.com/collectiveidea/money/commit/04e2ecb07eefe4e0c2a1621281ecc0c0ceec8a71</url>
  <id>04e2ecb07eefe4e0c2a1621281ecc0c0ceec8a71</id>
  <committed-date>2009-07-22T12:23:26-07:00</committed-date>
  <authored-date>2009-07-22T12:23:26-07:00</authored-date>
  <message>Added the ability for :allow_nil to be set to false when declaring a money field, and it now properly defaults to -bash rather than nil</message>
  <tree>67746cec74dbdd6ec42b46b40c8407e9c54a4004</tree>
  <committer>
    <name>Zach Dennis</name>
    <email>zach.dennis@gmail.com</email>
  </committer>
</commit>
