Skip to content

Commit

Permalink
Revert "Merge pull request rails#4490 from EmmanuelOga/master"
Browse files Browse the repository at this point in the history
This behaviour doesn't actually make sense, the context of
the child should not be affected by the parent. See rails#10492.

This reverts commit 5f8274e, reversing
changes made to 81e837e.
  • Loading branch information
José Valim committed Jun 3, 2013
1 parent 2767f83 commit 75135a9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/autosave_association.rb
Expand Up @@ -301,7 +301,7 @@ def validate_collection_association(reflection)
def association_valid?(reflection, record)
return true if record.destroyed? || record.marked_for_destruction?

unless valid = record.valid?(validation_context)
unless valid = record.valid?
if reflection.options[:autosave]
record.errors.each do |attribute, message|
attribute = "#{reflection.name}.#{attribute}"
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations/associated.rb
Expand Up @@ -2,7 +2,7 @@ module ActiveRecord
module Validations
class AssociatedValidator < ActiveModel::EachValidator #:nodoc:
def validate_each(record, attribute, value)
if Array.wrap(value).reject {|r| r.marked_for_destruction? || r.valid?(record.validation_context) }.any?
if Array.wrap(value).reject {|r| r.marked_for_destruction? || r.valid?}.any?
record.errors.add(attribute, :invalid, options.merge(:value => value))
end
end
Expand Down
17 changes: 0 additions & 17 deletions activerecord/test/cases/validations/association_validation_test.rb
Expand Up @@ -118,21 +118,4 @@ def test_validates_presence_of_belongs_to_association__existing_parent
end
end

def test_validates_associated_models_in_the_same_context
Topic.validates_presence_of :title, :on => :custom_context
Topic.validates_associated :replies
Reply.validates_presence_of :title, :on => :custom_context

t = Topic.new('title' => '')
r = t.replies.new('title' => '')

assert t.valid?
assert !t.valid?(:custom_context)

t.title = "Longer"
assert !t.valid?(:custom_context), "Should NOT be valid if the associated object is not valid in the same context."

r.title = "Longer"
assert t.valid?(:custom_context), "Should be valid if the associated object is not valid in the same context."
end
end

0 comments on commit 75135a9

Please sign in to comment.