public
Rubygem
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-more.git
Fixed issue with auto-validation

* Only pass through scale and precision to the numeric_validator
  if those values are explicitly specified in the property.
* Fixes issue #300, where a RegexpError was being
  thrown for auto-validations on Floats without a
  specified precision and scale.
myabc (author)
Thu May 22 05:32:30 -0700 2008
commit  c88cc4e939519922e2a45db629443b955204f966
tree    c751adcdeee6de89b93e12fdaecbce5848606537
parent  28e69c642b8a534837913e2e0b6ffb63a977348e
...
84
85
86
87
88
 
 
89
90
91
...
84
85
86
 
 
87
88
89
90
91
0
@@ -84,8 +84,8 @@ module DataMapper
0
           opts[:integer_only] = true
0
           validates_is_number property.name, opts
0
         elsif BigDecimal == property.type || Float == property.type
0
-          opts[:precision] = property.precision
0
-          opts[:scale]     = property.scale
0
+          opts[:precision] = property.precision if property.precision > 0
0
+          opts[:scale]     = property.scale     if property.scale != 10
0
           validates_is_number property.name, opts
0
         end
0
       end
...
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
0
@@ -52,4 +52,30 @@ describe DataMapper::Validate::NumericValidator do
0
     h = Hillary.new
0
     h.should be_valid
0
   end
0
+
0
+  it "should validate with autovalidate" do
0
+
0
+    class RobotFish
0
+      include DataMapper::Resource
0
+      property :id,     Integer, :serial => true
0
+      property :scales, Integer
0
+      property :average_weight, Float
0
+    end
0
+
0
+    class PondFish
0
+      include DataMapper::Resource
0
+      property :id,     Integer, :serial => true
0
+      property :scales, Integer
0
+      property :average_weight, Float, :scale => 10, :precision => 0, :auto_validation => false
0
+      validates_is_number :average_weight
0
+    end
0
+
0
+    fish1 = PondFish.new
0
+    fish2 = RobotFish.new
0
+    fish1.scales = fish2.scales = 1
0
+    fish1.average_weight = fish2.average_weight = 20.22
0
+    fish1.valid?.should == true
0
+    fish2.valid?.should == true
0
+  end
0
+
0
 end

Comments