From 1080351437dc43c3ecaa0d494f5ca215f03b1883 Mon Sep 17 00:00:00 2001 From: Bryan Stearns Date: Wed, 30 Sep 2009 23:17:50 -0700 Subject: Add failing test that triggers the stack overflow --- activerecord/test/models/invoice.rb | 4 ++++ activerecord/test/models/line_item.rb | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 activerecord/test/models/invoice.rb create mode 100644 activerecord/test/models/line_item.rb (limited to 'activerecord/test/models') 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 -- cgit v1.2.3 From f2aacd51405724cdf7cfd36a439c9dbfce16973a Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Fri, 8 Jan 2010 20:47:49 +0100 Subject: Rollback the transaction when one of the autosave associations fails to save. [#3391 state:resolved] --- activerecord/test/models/bird.rb | 6 ++++++ activerecord/test/models/parrot.rb | 6 ++++++ activerecord/test/models/pirate.rb | 6 ++++++ activerecord/test/models/ship.rb | 6 ++++++ 4 files changed, 24 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/bird.rb b/activerecord/test/models/bird.rb index 341d2eeffc..e61d48e6a5 100644 --- a/activerecord/test/models/bird.rb +++ b/activerecord/test/models/bird.rb @@ -1,3 +1,9 @@ class Bird < ActiveRecord::Base validates_presence_of :name + + attr_accessor :cancel_save_from_callback + before_save :cancel_save_callback_method, :if => :cancel_save_from_callback + def cancel_save_callback_method + false + end end \ No newline at end of file diff --git a/activerecord/test/models/parrot.rb b/activerecord/test/models/parrot.rb index 4a7ed52636..737ef9131b 100644 --- a/activerecord/test/models/parrot.rb +++ b/activerecord/test/models/parrot.rb @@ -6,6 +6,12 @@ class Parrot < ActiveRecord::Base alias_attribute :title, :name validates_presence_of :name + + attr_accessor :cancel_save_from_callback + before_save :cancel_save_callback_method, :if => :cancel_save_from_callback + def cancel_save_callback_method + false + end end class LiveParrot < Parrot diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb index 88c1634717..f1dbe32c6e 100644 --- a/activerecord/test/models/pirate.rb +++ b/activerecord/test/models/pirate.rb @@ -51,6 +51,12 @@ class Pirate < ActiveRecord::Base attributes.delete('_reject_me_if_new').present? && new_record? end + attr_accessor :cancel_save_from_callback + before_save :cancel_save_callback_method, :if => :cancel_save_from_callback + def cancel_save_callback_method + false + end + private def log_before_add(record) log(record, "before_adding_method") diff --git a/activerecord/test/models/ship.rb b/activerecord/test/models/ship.rb index a96e38ab41..75c792d176 100644 --- a/activerecord/test/models/ship.rb +++ b/activerecord/test/models/ship.rb @@ -9,4 +9,10 @@ class Ship < ActiveRecord::Base accepts_nested_attributes_for :update_only_pirate, :update_only => true validates_presence_of :name + + attr_accessor :cancel_save_from_callback + before_save :cancel_save_callback_method, :if => :cancel_save_from_callback + def cancel_save_callback_method + false + end end -- cgit v1.2.3