<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -84,8 +84,8 @@ module DataMapper
           opts[:integer_only] = true
           validates_is_number property.name, opts
         elsif BigDecimal == property.type || Float == property.type
-          opts[:precision] = property.precision if property.precision &gt; 0
-          opts[:scale]     = property.scale     if property.scale != 10
+          opts[:precision] = property.precision
+          opts[:scale]     = property.scale
           validates_is_number property.name, opts
         end
       end</diff>
      <filename>dm-validations/lib/dm-validations/auto_validate.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,13 @@ module DataMapper
           error_message ||= '%s must be an integer'.t(DataMapper::Inflection.humanize(@field_name))
         else
           if scale &amp;&amp; precision
-            return true if value =~ /\A(?:\d{1,#{scale - precision}}|\d{0,#{scale - precision}}\.\d{1,#{precision}})\z/
+            if scale == precision
+              return true if value =~ /\A(?:0\.\d{1,#{precision}})\z/
+            elsif precision == 0
+              return true if value =~ /\A(?:\d{1,#{scale}}(?:\.0)?)\z/
+            else
+              return true if value =~ /\A(?:\d{1,#{scale - precision}}|\d{0,#{scale - precision}}\.\d{1,#{precision}})\z/
+            end
           else
             return true if value =~ /\A(?:\d+|\d*\.\d+)\z/
           end</diff>
      <filename>dm-validations/lib/dm-validations/numeric_validator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -53,29 +53,116 @@ describe DataMapper::Validate::NumericValidator do
     h.should be_valid
   end
 
-  it &quot;should validate with autovalidate&quot; do
-
-    class RobotFish
-      include DataMapper::Resource
-      property :id,     Integer, :serial =&gt; true
-      property :scales, Integer
-      property :average_weight, Float
+  describe 'auto validation' do
+    before :all do
+      class Fish
+        include DataMapper::Resource
+        property :id,     Integer, :serial =&gt; true
+        property :scales, Integer
+      end
     end
 
-    class PondFish
-      include DataMapper::Resource
-      property :id,     Integer, :serial =&gt; true
-      property :scales, Integer
-      property :average_weight, Float, :scale =&gt; 10, :precision =&gt; 0, :auto_validation =&gt; false
-      validates_is_number :average_weight
-    end
+    describe 'Float' do
+      describe 'with default scale and precision' do
+        before :all do
+          class RobotFish &lt; Fish
+            property :average_weight, Float
+          end
+        end
 
-    fish1 = PondFish.new
-    fish2 = RobotFish.new
-    fish1.scales = fish2.scales = 1
-    fish1.average_weight = fish2.average_weight = 20.22
-    fish1.valid?.should == true
-    fish2.valid?.should == true
-  end
+        before do
+          @robot_fish = RobotFish.new
+        end
+
+        it 'should allow up to 10 digits before the decimal' do
+          @robot_fish.average_weight = 0
+          @robot_fish.should be_valid
+
+          @robot_fish.average_weight = 9_999_999_999
+          @robot_fish.should be_valid
+
+          @robot_fish.average_weight = 10_000_000_000
+          @robot_fish.should_not be_valid
+        end
+
+        it 'should allow 0 digits of precision after the decimal' do
+          @robot_fish.average_weight = 0
+          @robot_fish.should be_valid
+        end
+
+        it 'should allow 1 digit of precision after the decimal if it is a zero' do
+          @robot_fish.average_weight = 0.0
+          @robot_fish.should be_valid
+
+          @robot_fish.average_weight = 9_999_999_999.0
+          @robot_fish.should be_valid
+
+          @robot_fish.average_weight = 0.1
+          @robot_fish.should_not be_valid
+        end
+      end
+
+      describe 'with a scale of 4 and a precision of 2' do
+        before :all do
+          class GoldFish &lt; Fish
+            property :average_weight, Float, :scale =&gt; 4, :precision =&gt; 2
+          end
+        end
+
+        before do
+          @gold_fish = GoldFish.new
+        end
+
+        it 'should allow up to 2 digits before the decimal' do
+          @gold_fish.average_weight = 0
+          @gold_fish.should be_valid
 
+          @gold_fish.average_weight = 99
+          @gold_fish.should be_valid
+
+          @gold_fish.average_weight = 100
+          @gold_fish.should_not be_valid
+        end
+
+        it 'should allow 2 digits of precision after the decimal' do
+          @gold_fish.average_weight = 99.99
+          @gold_fish.should be_valid
+
+          @gold_fish.average_weight = 99.999
+          @gold_fish.should_not be_valid
+        end
+      end
+
+      describe 'with a scale of 2 and a precision of 2' do
+        before :all do
+          class SilverFish &lt; Fish
+            property :average_weight, Float, :scale =&gt; 2, :precision =&gt; 2
+          end
+        end
+
+        before do
+          @silver_fish = SilverFish.new
+        end
+
+        it 'should allow a 0 before the decimal' do
+          @silver_fish.average_weight = 0
+          @silver_fish.should be_valid
+
+          @silver_fish.average_weight = 0.1
+          @silver_fish.should be_valid
+
+          @silver_fish.average_weight = 1
+          @silver_fish.should_not be_valid
+        end
+
+        it 'should allow 2 digits of precision after the decimal' do
+          @silver_fish.average_weight = 0.99
+          @silver_fish.should be_valid
+
+          @silver_fish.average_weight = 0.999
+          @silver_fish.should_not be_valid
+        end
+      end
+    end
+  end
 end</diff>
      <filename>dm-validations/spec/integration/numeric_validator_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0ff796fa8fe64e1125c74bfd1be405f338fdab9d</id>
    </parent>
  </parents>
  <author>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </author>
  <url>http://github.com/sam/dm-more/commit/0765e3cd805059b3d8f01b480d42918538635fa7</url>
  <id>0765e3cd805059b3d8f01b480d42918538635fa7</id>
  <committed-date>2008-05-25T17:39:48-07:00</committed-date>
  <authored-date>2008-05-25T17:39:48-07:00</authored-date>
  <message>Added specs for numeric validator

* Fixed bug when precision == scale
* Fix for ticket #300</message>
  <tree>34214d1c19071901415fe11ee8235552f3ca066a</tree>
  <committer>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </committer>
</commit>
