Ticket #8241: remove_warning_in_validates_presence_of_docs.patch
| File remove_warning_in_validates_presence_of_docs.patch, 2.9 kB (added by quixoten, 2 years ago) |
|---|
-
lib/active_record/validations.rb
old new 448 448 # * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should 449 449 # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The 450 450 # method, proc or string should return or evaluate to a true or false value. 451 #452 # === Warning453 # Validate the presence of the foreign key, not the instance variable itself.454 # Do this:455 # validates_presence_of :invoice_id456 #457 # Not this:458 # validates_presence_of :invoice459 #460 # If you validate the presence of the associated object, you will get461 # failures on saves when both the parent object and the child object are462 # new.463 451 def validates_presence_of(*attr_names) 464 452 configuration = { :message => ActiveRecord::Errors.default_error_messages[:blank], :on => :save } 465 453 configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) -
test/validations_test.rb
old new 2 2 require 'fixtures/topic' 3 3 require 'fixtures/reply' 4 4 require 'fixtures/person' 5 require 'fixtures/reader' 5 6 require 'fixtures/developer' 6 7 7 8 # The following methods in Topic are used in test_conditional_validation_* … … 28 29 Topic.write_inheritable_attribute(:validate, nil) 29 30 Topic.write_inheritable_attribute(:validate_on_create, nil) 30 31 Topic.write_inheritable_attribute(:validate_on_update, nil) 32 33 Reader.write_inheritable_attribute(:validate, nil) 34 Person.write_inheritable_attribute(:validate, nil) 31 35 end 32 36 33 37 def test_single_field_validation … … 276 280 277 281 assert t.save 278 282 end 283 284 def test_validate_presence_of_belongs_to_association_with_unsaved_parent_and_child 285 Reader.validates_presence_of :person 286 287 child = Reader.new(:post_id => '1') 288 assert !child.save 289 assert_equal "can't be blank", child.errors.on(:person) 290 291 parent = child.person = Person.new() 292 assert child.new_record? 293 assert parent.new_record? 294 assert child.save 295 end 296 297 def test_validate_presence_of_has_many_association_with_unsaved_parent_and_child 298 Person.validates_presence_of :readers 299 300 parent = Person.new() 301 assert !parent.save 302 assert_equal "can't be blank", parent.errors.on(:readers) 303 304 child = parent.readers = [Reader.new(:post_id => '1')] 305 assert parent.new_record? 306 assert parent.readers[0].new_record? 307 assert parent.save 308 end 279 309 280 310 def test_validate_uniqueness 281 311 Topic.validates_uniqueness_of(:title)