Skip to content

Commit 2aef092

Browse files
bryanstearnsalloy
authored andcommitted
Add failing test that triggers the stack overflow for #2578.
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
1 parent d5ba7c3 commit 2aef092

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

activerecord/test/cases/autosave_association_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'models/company'
44
require 'models/customer'
55
require 'models/developer'
6+
require 'models/invoice'
7+
require 'models/line_item'
68
require 'models/order'
79
require 'models/parrot'
810
require 'models/person'
@@ -1169,3 +1171,10 @@ def setup
11691171
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_parrots)
11701172
end
11711173
end
1174+
1175+
class TestAutosaveAssociationWithTouch < ActiveRecord::TestCase
1176+
def test_autosave_with_touch_should_not_raise_system_stack_error
1177+
invoice = Invoice.create
1178+
assert_nothing_raised { invoice.line_items.create(:amount => 10) }
1179+
end
1180+
end

activerecord/test/models/invoice.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Invoice < ActiveRecord::Base
2+
has_many :line_items, :autosave => true
3+
before_save {|record| record.balance = record.line_items.map(&:amount).sum }
4+
end

activerecord/test/models/line_item.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class LineItem < ActiveRecord::Base
2+
belongs_to :invoice, :touch => true
3+
end

activerecord/test/schema/schema.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ def create_table(*args, &block)
192192
t.string :info
193193
end
194194

195+
create_table :invoices, :force => true do |t|
196+
t.integer :balance
197+
t.datetime :updated_at
198+
end
199+
195200
create_table :items, :force => true do |t|
196201
t.column :name, :integer
197202
end
@@ -217,6 +222,11 @@ def create_table(*args, &block)
217222
t.integer :version, :null => false, :default => 0
218223
end
219224

225+
create_table :line_items, :force => true do |t|
226+
t.integer :invoice_id
227+
t.integer :amount
228+
end
229+
220230
create_table :lock_without_defaults, :force => true do |t|
221231
t.column :lock_version, :integer
222232
end

0 commit comments

Comments
 (0)