Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/activerecord/delay_touching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@
end
end

it 'enters an infinite loop on polymorphic association raising an exception before create' do
person = Person.new(name: 'Foo')
person.pictures.build(owner: person, name: 'foo')
person.pictures.build(owner: person, name: 'error')
ActiveRecord::Base.delay_touching do
person.save
end
end

context 'touch: true' do
before do
person.pets << pet1
Expand Down
15 changes: 15 additions & 0 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
class Person < ActiveRecord::Base
has_many :pets, inverse_of: :person
has_many :pictures, as: :owner
end

class Pet < ActiveRecord::Base
belongs_to :person, touch: true, inverse_of: :pets
end

class Picture < ActiveRecord::Base
belongs_to :owner, polymorphic: true, touch: true

before_save :raise_an_exception

def raise_an_exception
if name == "error"
raise "Cannot save picture"
else
true
end
end
end
7 changes: 7 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
t.timestamps
end

create_table :pictures, :force => true do |t|
t.string :name
t.string :owner_type
t.integer :owner_id

t.timestamps
end
end