0
@@ -2,6 +2,7 @@ require "cases/helper"
0
require 'models/developer'
0
class TransactionTest < ActiveRecord::TestCase
0
self.use_transactional_fixtures = false
0
@@ -86,8 +87,7 @@ class TransactionTest < ActiveRecord::TestCase
0
assert Topic.find(2).approved?, "Second should still be approved"
0
- def test_callback_rollback_in_save
0
+ def test_raising_exception_in_callback_rollbacks_in_save
0
add_exception_raising_after_save_callback_to_topic
0
@@ -102,6 +102,54 @@ class TransactionTest < ActiveRecord::TestCase
0
+ def test_cancellation_from_before_destroy_rollbacks_in_destroy
0
+ add_cancelling_before_destroy_with_db_side_effect_to_topic
0
+ nbooks_before_destroy = Book.count
0
+ status = @first.destroy
0
+ assert_nothing_raised(ActiveRecord::RecordNotFound) { @first.reload }
0
+ assert_equal nbooks_before_destroy, Book.count
0
+ remove_cancelling_before_destroy_with_db_side_effect_to_topic
0
+ def test_cancellation_from_before_filters_rollbacks_in_save
0
+ %w(validation save).each do |filter|
0
+ send("add_cancelling_before_#{filter}_with_db_side_effect_to_topic")
0
+ nbooks_before_save = Book.count
0
+ original_author_name = @first.author_name
0
+ @first.author_name += '_this_should_not_end_up_in_the_db'
0
+ assert_equal original_author_name, @first.reload.author_name
0
+ assert_equal nbooks_before_save, Book.count
0
+ send("remove_cancelling_before_#{filter}_with_db_side_effect_to_topic")
0
+ def test_cancellation_from_before_filters_rollbacks_in_save!
0
+ %w(validation save).each do |filter|
0
+ send("add_cancelling_before_#{filter}_with_db_side_effect_to_topic")
0
+ nbooks_before_save = Book.count
0
+ original_author_name = @first.author_name
0
+ @first.author_name += '_this_should_not_end_up_in_the_db'
0
+ assert_equal original_author_name, @first.reload.author_name
0
+ assert_equal nbooks_before_save, Book.count
0
+ send("remove_cancelling_before_#{filter}_with_db_side_effect_to_topic")
0
def test_callback_rollback_in_create
0
:title => "A new topic",
0
@@ -221,6 +269,16 @@ class TransactionTest < ActiveRecord::TestCase
0
def remove_exception_raising_after_create_callback_to_topic
0
Topic.class_eval { remove_method :after_create }
0
+ %w(validation save destroy).each do |filter|
0
+ define_method("add_cancelling_before_#{filter}_with_db_side_effect_to_topic") do
0
+ Topic.class_eval "def before_#{filter}() Book.create; false end"
0
+ define_method("remove_cancelling_before_#{filter}_with_db_side_effect_to_topic") do
0
+ Topic.class_eval "remove_method :before_#{filter}"
0
if current_adapter?(:PostgreSQLAdapter)