From 27aa4dda7d89ce7332e6d1f3266c3a0cf1c3fb9e Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 10 Jan 2015 16:46:57 -0500 Subject: Fix validations on child record when record parent has validate: false Fixes #17621. This 5 year old (or older) issue causes validations to fire when a parent record has `validate: false` option and a child record is saved. It's not the responsibility of the model to validate an associated object unless the object was created or modified by the parent. Clean up tests related to validations `assert_nothing_raised` is not benefiting us in these tests Corrected spelling of "respects" It's better to use `assert_not_operator` over `assert !r.valid` --- activerecord/lib/active_record/validations/presence.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib/active_record/validations/presence.rb') diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb index 61b30749d9..75d5bd5a35 100644 --- a/activerecord/lib/active_record/validations/presence.rb +++ b/activerecord/lib/active_record/validations/presence.rb @@ -2,6 +2,7 @@ module ActiveRecord module Validations class PresenceValidator < ActiveModel::Validations::PresenceValidator # :nodoc: def validate(record) + return unless should_validate?(record) super attributes.each do |attribute| next unless record.class._reflect_on_association(attribute) -- cgit v1.2.3