File tree Expand file tree Collapse file tree 4 files changed +22
-13
lines changed Expand file tree Collapse file tree 4 files changed +22
-13
lines changed Original file line number Diff line number Diff line change 1
1
Version 1.0 - June 1, 2010
2
2
3
+ - fixed validates_numericality_of to not ignore other options when only_integer is present and matches
3
4
- fixed set methods on DateTime objects to properly flag attributes as dirty
4
5
- fixed DateTime attributes to be serialized as strings
5
6
- support for Oracle
@@ -13,4 +14,4 @@ Version 1.0 - June 1, 2010
13
14
- added validates_uniqueness_of
14
15
- added dynamic count_by
15
16
- added eager loading
16
- - and many bug fixes
17
+ - and many bug fixes
Original file line number Diff line number Diff line change @@ -288,16 +288,16 @@ public function validates_numericality_of($attrs)
288
288
289
289
if (true === $ options ['only_integer ' ] && !is_integer ($ var ))
290
290
{
291
- if (preg_match ('/\A[+-]?\d+\Z/ ' , (string )($ var )))
292
- break ;
293
-
294
- if (isset ($ options ['message ' ]))
295
- $ message = $ options ['message ' ];
296
- else
297
- $ message = Errors::$ DEFAULT_ERROR_MESSAGES ['not_a_number ' ];
291
+ if (!preg_match ('/\A[+-]?\d+\Z/ ' , (string )($ var )))
292
+ {
293
+ if (isset ($ options ['message ' ]))
294
+ $ message = $ options ['message ' ];
295
+ else
296
+ $ message = Errors::$ DEFAULT_ERROR_MESSAGES ['not_a_number ' ];
298
297
299
- $ this ->record ->add ($ attribute , $ message );
300
- continue ;
298
+ $ this ->record ->add ($ attribute , $ message );
299
+ continue ;
300
+ }
301
301
}
302
302
else
303
303
{
Original file line number Diff line number Diff line change @@ -102,6 +102,14 @@ public function test_only_integer()
102
102
$ this ->assert_invalid (array (1.5 , '1.5 ' ));
103
103
}
104
104
105
+ public function test_only_integer_matching_does_not_ignore_other_options ()
106
+ {
107
+ BookNumericality::$ validates_numericality_of [0 ]['only_integer ' ] = true ;
108
+ BookNumericality::$ validates_numericality_of [0 ]['greater_than ' ] = 0 ;
109
+
110
+ $ this ->assert_invalid (array (-1 ,'-1 ' ));
111
+ }
112
+
105
113
public function test_greater_than ()
106
114
{
107
115
BookNumericality::$ validates_numericality_of [0 ]['greater_than ' ] = 5 ;
@@ -145,4 +153,4 @@ public function test_greater_than_less_than_and_even()
145
153
146
154
array_merge (ValidatesNumericalityOfTest::$ INTEGERS , ValidatesNumericalityOfTest::$ INTEGER_STRINGS );
147
155
array_merge (ValidatesNumericalityOfTest::$ FLOATS , ValidatesNumericalityOfTest::$ FLOAT_STRINGS );
148
- ?>
156
+ ?>
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class BookValidations extends ActiveRecord\Model
9
9
static $ alias_attribute = array ('name_alias ' => 'name ' , 'x ' => 'secondary_author_id ' );
10
10
static $ validates_presence_of = array (array ('name ' ));
11
11
static $ validates_uniqueness_of = array ();
12
- };
12
+ }
13
13
14
14
class ValidationsTest extends DatabaseTest
15
15
{
@@ -115,4 +115,4 @@ public function test_get_validation_rules()
115
115
$ this ->assert_true (in_array (array ('validator ' => 'validates_presence_of ' ),$ validators ['name ' ]));
116
116
}
117
117
};
118
- ?>
118
+ ?>
You can’t perform that action at this time.
0 commit comments