Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

context in validation goes through has many relationship #13978

Merged
merged 1 commit into from

2 participants

@Fortisque

this resolves #13854

@tenderlove tenderlove merged commit f99b254 into rails:master

1 check passed

Details default The Travis CI build passed
@huoxito huoxito referenced this pull request from a commit in huoxito/spree
@huoxito huoxito Create real Order object in promotion_spec
See rails/rails#13978

It looks like it broke rspec-rails stub_model implementation when
assigning that stub to its parent. (in a has many context)

A similar case also happens with mock_model (failing with *unexpected
message attribute*)
383ee51
@huoxito huoxito referenced this pull request from a commit in spree/spree
@huoxito huoxito Use stub_model rathen than mock_model
Make rails 4.0.4 build happy
2e8fee9
@huoxito huoxito referenced this pull request from a commit in spree/spree
@huoxito huoxito Create real Order object in promotion_spec
See rails/rails#13978

It looks like it broke rspec-rails stub_model implementation when
assigning that stub to its parent. (in a has many context)

A similar case also happens with mock_model (failing with *unexpected
message attribute*)
795f17e
@radar radar referenced this pull request from a commit in radar/spree
@huoxito huoxito Create real Order object in promotion_spec
See rails/rails#13978

It looks like it broke rspec-rails stub_model implementation when
assigning that stub to its parent. (in a has many context)

A similar case also happens with mock_model (failing with *unexpected
message attribute*)
c2b81d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  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?
+ unless valid = record.valid?(self.validation_context)
if reflection.options[:autosave]
record.errors.each do |attribute, message|
attribute = "#{reflection.name}.#{attribute}"
View
10 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -22,6 +22,8 @@
require 'models/categorization'
require 'models/minivan'
require 'models/speedometer'
+require 'models/pirate'
+require 'models/ship'
class HasManyAssociationsTestForReorderWithJoinDependency < ActiveRecord::TestCase
fixtures :authors, :posts, :comments
@@ -1830,4 +1832,12 @@ def test_collection_association_with_private_kernel_method
end
end
end
+
+ test 'has_many_association passes context validation to validate children' do
+ pirate = FamousPirate.new
+ pirate.famous_ships << ship = FamousShip.new
+ assert_equal true, pirate.valid?
+ assert_equal false, pirate.valid?(:conference)
+ assert_equal "can't be blank", ship.errors[:name].first
+ end
end
View
8 activerecord/test/models/pirate.rb
@@ -85,3 +85,11 @@ def log(record, callback)
class DestructivePirate < Pirate
has_one :dependent_ship, :class_name => 'Ship', :foreign_key => :pirate_id, :dependent => :destroy
end
+
+class FamousPirate < ActiveRecord::Base
+ self.table_name = 'pirates'
+
+ has_many :famous_ships
+
+ validates_presence_of :catchphrase, on: :conference
+end
View
8 activerecord/test/models/ship.rb
@@ -17,3 +17,11 @@ def cancel_save_callback_method
false
end
end
+
+class FamousShip < ActiveRecord::Base
+ self.table_name = 'ships'
+
+ belongs_to :famous_pirate
+
+ validates_presence_of :name, on: :conference
+end
Something went wrong with that request. Please try again.