aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorWill Jessop <will@willj.net>2019-07-13 20:52:32 +0100
committerWill Jessop <will@willj.net>2019-07-15 18:21:20 +0100
commit6ea80b6103de9ef76dca9d51149dd94bec846642 (patch)
treea95a56cfd09163e4c79ac95af69d0afb467c2126 /activerecord/test/models
parent88b91299f3fc5b912e10323ed0ad18c87c7584e5 (diff)
downloadrails-6ea80b6103de9ef76dca9d51149dd94bec846642.tar.gz
rails-6ea80b6103de9ef76dca9d51149dd94bec846642.tar.bz2
rails-6ea80b6103de9ef76dca9d51149dd94bec846642.zip
Don't validate non dirty association targets
Fixes #36581. This fixes an issue where validations would return differently when a previously saved invalid association was loaded between calls: assert_equal true, squeak.valid? assert_equal true, squeak.mouse.present? assert_equal true, squeak.valid? Here the second assert would return Expected: true Actual: false Limiting validations to associations that would be normally saved (using autosave: true) due to changes means that loading invalid associated relations will not change the return value of the parent relations's `valid?` method.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/mouse.rb6
-rw-r--r--activerecord/test/models/squeak.rb6
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/models/mouse.rb b/activerecord/test/models/mouse.rb
new file mode 100644
index 0000000000..75a55c125d
--- /dev/null
+++ b/activerecord/test/models/mouse.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+class Mouse < ActiveRecord::Base
+ has_many :squeaks, autosave: true
+ validates :name, presence: true
+end
diff --git a/activerecord/test/models/squeak.rb b/activerecord/test/models/squeak.rb
new file mode 100644
index 0000000000..e0a643c238
--- /dev/null
+++ b/activerecord/test/models/squeak.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+class Squeak < ActiveRecord::Base
+ belongs_to :mouse
+ accepts_nested_attributes_for :mouse
+end