aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/rescuable_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/rescuable_test.rb')
-rw-r--r--activesupport/test/rescuable_test.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb
index ff77e16edd..1c74ce8b2a 100644
--- a/activesupport/test/rescuable_test.rb
+++ b/activesupport/test/rescuable_test.rb
@@ -9,11 +9,16 @@ end
class MadRonon < StandardError
end
+class CoolError < StandardError
+end
+
class Stargate
attr_accessor :result
include ActiveSupport::Rescuable
+ rescue_from WraithAttack, :with => :sos_first
+
rescue_from WraithAttack, :with => :sos
rescue_from NuclearExplosion do
@@ -45,11 +50,30 @@ class Stargate
def sos
@result = 'killed'
end
+
+ def sos_first
+ @result = 'sos_first'
+ end
+
+end
+
+class CoolStargate < Stargate
+ attr_accessor :result
+
+ include ActiveSupport::Rescuable
+
+ rescue_from CoolError, :with => :sos_cool_error
+
+ def sos_cool_error
+ @result = 'sos_cool_error'
+ end
end
+
class RescueableTest < Test::Unit::TestCase
def setup
@stargate = Stargate.new
+ @cool_stargate = CoolStargate.new
end
def test_rescue_from_with_method
@@ -66,4 +90,17 @@ class RescueableTest < Test::Unit::TestCase
@stargate.dispatch :ronanize
assert_equal 'dex', @stargate.result
end
+
+ def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array
+ expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon"]
+ result = @stargate.send(:rescue_handlers).collect {|e| e.first}
+ assert_equal expected, result
+ end
+
+ def test_children_should_inherit_rescue_defintions_from_parents_and_child_rescue_should_be_appended
+ expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "CoolError"]
+ result = @cool_stargate.send(:rescue_handlers).collect {|e| e.first}
+ assert_equal expected, result
+ end
+
end