From 7655fc0b6c7b0593fb73fe1d6b6beddba152f6fe Mon Sep 17 00:00:00 2001 From: wangjohn Date: Fri, 31 May 2013 10:00:58 -0400 Subject: [PATCH 1/2] Fixing a failing railtie test by using the ENV variable to specify a particular controller to search for in rake routes. --- railties/test/application/rake_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 00a4ab06aaa6c..cfa5cc1322201 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -159,7 +159,8 @@ def test_rake_routes_with_controller_environment end RUBY - output = Dir.chdir(app_path){ `CONTROLLER=cart rake routes` } + ENV['CONTROLLER'] = 'cart' + output = Dir.chdir(app_path){ `rake routes` } assert_equal "Prefix Verb URI Pattern Controller#Action\ncart GET /cart(.:format) cart#show\n", output end From 75135a97907b4bdeb51eefaaaf8bd35215206fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 4 Jun 2013 00:33:50 +0900 Subject: [PATCH 2/2] Revert "Merge pull request #4490 from EmmanuelOga/master" This behaviour doesn't actually make sense, the context of the child should not be affected by the parent. See #10492. This reverts commit 5f8274efe128ffeec8fa3179460f5167a078f007, reversing changes made to 81e837e810460d066a2e5fc5a795366ec8ab2313. --- .../lib/active_record/autosave_association.rb | 2 +- .../lib/active_record/validations/associated.rb | 2 +- .../validations/association_validation_test.rb | 17 ----------------- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 87d4daa6d94d9..a8a184755468b 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -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}" diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index 744780d069e2b..b4785d3ba45a5 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -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 diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb index 7ac34bc71eae4..7e92a2b127f39 100644 --- a/activerecord/test/cases/validations/association_validation_test.rb +++ b/activerecord/test/cases/validations/association_validation_test.rb @@ -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