Permalink
Browse files

while defining callbacks option :rescuable => true

can be passed. There were no tests for this case.

This patch adds a test for :rescuable => true
option.
  • Loading branch information...
1 parent 6b43a3a commit 27d0d4fffdb62d221e124b67b7ee3de6bfa1893b Neeraj Singh committed with josevalim Dec 17, 2010
Showing with 30 additions and 1 deletion.
  1. +30 −1 activesupport/test/callbacks_test.rb
@@ -3,6 +3,27 @@
require 'active_support'
module CallbacksTest
+ class Phone
+ include ActiveSupport::Callbacks
+ define_callbacks :save, :rescuable => true
+
+ set_callback :save, :before, :before_save1
+ set_callback :save, :after, :after_save1
+
+ def before_save1; self.history << :before; end
+ def after_save1; self.history << :after; end
+
+ def save
+ self.send(:_run_save_callbacks) do
+ raise 'boom'
+ end
+ end
+
+ def history
+ @history ||= []
+ end
+ end
+
class Record
include ActiveSupport::Callbacks
@@ -338,6 +359,14 @@ def test_skip_person
end
class CallbacksTest < Test::Unit::TestCase
+ def test_save_phone
+ phone = Phone.new
+ assert_raise RuntimeError do
+ phone.save
+ end
+ assert_equal [:before, :after], phone.history
+ end
+
def test_save_person
person = Person.new
assert_equal [], person.history
@@ -573,5 +602,5 @@ def test_skip_writer
], writer.history
end
end
-
+
end

0 comments on commit 27d0d4f

Please sign in to comment.