aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Stearns <bryanstearns@gmail.com>2009-09-30 23:17:50 -0700
committerEloy Duran <eloy.de.enige@gmail.com>2010-01-08 21:45:02 +0100
commit1080351437dc43c3ecaa0d494f5ca215f03b1883 (patch)
tree371ebdf25e1ab947ae9ece41b959b9b6dc0f5a2b
parent802b08da0075bf6426c723957447ed85dc849bba (diff)
downloadrails-1080351437dc43c3ecaa0d494f5ca215f03b1883.tar.gz
rails-1080351437dc43c3ecaa0d494f5ca215f03b1883.tar.bz2
rails-1080351437dc43c3ecaa0d494f5ca215f03b1883.zip
Add failing test that triggers the stack overflow
-rw-r--r--activerecord/test/cases/autosave_association_test.rb9
-rw-r--r--activerecord/test/models/invoice.rb4
-rw-r--r--activerecord/test/models/line_item.rb3
-rw-r--r--activerecord/test/schema/schema.rb10
4 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index 116c8fc509..97d75b651b 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -3,6 +3,8 @@ require 'models/bird'
require 'models/company'
require 'models/customer'
require 'models/developer'
+require 'models/invoice'
+require 'models/line_item'
require 'models/order'
require 'models/parrot'
require 'models/person'
@@ -1215,3 +1217,10 @@ class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCas
assert !@pirate.respond_to?(:validate_associated_records_for_non_validated_parrots)
end
end
+
+class TestAutosaveAssociationWithTouch < ActiveRecord::TestCase
+ def test_autosave_with_touch_should_not_raise_system_stack_error
+ invoice = Invoice.create
+ assert_nothing_raised { invoice.line_items.create(:amount => 10) }
+ end
+end
diff --git a/activerecord/test/models/invoice.rb b/activerecord/test/models/invoice.rb
new file mode 100644
index 0000000000..fc6ef0230e
--- /dev/null
+++ b/activerecord/test/models/invoice.rb
@@ -0,0 +1,4 @@
+class Invoice < ActiveRecord::Base
+ has_many :line_items, :autosave => true
+ before_save {|record| record.balance = record.line_items.map(&:amount).sum }
+end
diff --git a/activerecord/test/models/line_item.rb b/activerecord/test/models/line_item.rb
new file mode 100644
index 0000000000..0dd921a300
--- /dev/null
+++ b/activerecord/test/models/line_item.rb
@@ -0,0 +1,3 @@
+class LineItem < ActiveRecord::Base
+ belongs_to :invoice, :touch => true
+end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 1ec36e7832..bec4291457 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -191,6 +191,11 @@ ActiveRecord::Schema.define do
t.string :info
end
+ create_table :invoices, :force => true do |t|
+ t.integer :balance
+ t.datetime :updated_at
+ end
+
create_table :items, :force => true do |t|
t.column :name, :integer
end
@@ -216,6 +221,11 @@ ActiveRecord::Schema.define do
t.integer :version, :null => false, :default => 0
end
+ create_table :line_items, :force => true do |t|
+ t.integer :invoice_id
+ t.integer :amount
+ end
+
create_table :lock_without_defaults, :force => true do |t|
t.column :lock_version, :integer
end