aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/new_callback_inheritance_test.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-10-12 22:15:43 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-12 22:15:43 -0500
commit21e7b8462113fc7c0fd1882dcc2bf7225de67b1a (patch)
tree81350780f50b8378aec99210d956bba3dda635f7 /activesupport/test/new_callback_inheritance_test.rb
parent9bc8defe38253840ceb9c4ad92e7c3abc0066ed8 (diff)
downloadrails-21e7b8462113fc7c0fd1882dcc2bf7225de67b1a.tar.gz
rails-21e7b8462113fc7c0fd1882dcc2bf7225de67b1a.tar.bz2
rails-21e7b8462113fc7c0fd1882dcc2bf7225de67b1a.zip
Callbacks, DeprecatedCallbacks = NewCallbacks, Callbacks
Diffstat (limited to 'activesupport/test/new_callback_inheritance_test.rb')
-rw-r--r--activesupport/test/new_callback_inheritance_test.rb115
1 files changed, 0 insertions, 115 deletions
diff --git a/activesupport/test/new_callback_inheritance_test.rb b/activesupport/test/new_callback_inheritance_test.rb
deleted file mode 100644
index fe316ae3da..0000000000
--- a/activesupport/test/new_callback_inheritance_test.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-require 'test/unit'
-$:.unshift "#{File.dirname(__FILE__)}/../lib"
-require 'active_support'
-
-class GrandParent
- include ActiveSupport::NewCallbacks
-
- attr_reader :log, :action_name
- def initialize(action_name)
- @action_name, @log = action_name, []
- end
-
- define_callbacks :dispatch
- set_callback :dispatch, :before, :before1, :before2, :per_key => {:if => proc {|c| c.action_name == "index" || c.action_name == "update" }}
- set_callback :dispatch, :after, :after1, :after2, :per_key => {:if => proc {|c| c.action_name == "update" || c.action_name == "delete" }}
-
- def before1
- @log << "before1"
- end
-
- def before2
- @log << "before2"
- end
-
- def after1
- @log << "after1"
- end
-
- def after2
- @log << "after2"
- end
-
- def dispatch
- _run_dispatch_callbacks(action_name) do
- @log << action_name
- end
- self
- end
-end
-
-class Parent < GrandParent
- skip_callback :dispatch, :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}
- skip_callback :dispatch, :after, :after2, :per_key => {:unless => proc {|c| c.action_name == "delete" }}
-end
-
-class Child < GrandParent
- skip_callback :dispatch, :before, :before2, :per_key => {:unless => proc {|c| c.action_name == "update" }}, :if => :state_open?
-
- def state_open?
- @state == :open
- end
-
- def initialize(action_name, state)
- super(action_name)
- @state = state
- end
-end
-
-
-class BasicCallbacksTest < Test::Unit::TestCase
- def setup
- @index = GrandParent.new("index").dispatch
- @update = GrandParent.new("update").dispatch
- @delete = GrandParent.new("delete").dispatch
- @unknown = GrandParent.new("unknown").dispatch
- end
-
- def test_basic_per_key1
- assert_equal %w(before1 before2 index), @index.log
- end
-
- def test_basic_per_key2
- assert_equal %w(before1 before2 update after2 after1), @update.log
- end
-
- def test_basic_per_key3
- assert_equal %w(delete after2 after1), @delete.log
- end
-end
-
-class InheritedCallbacksTest < Test::Unit::TestCase
- def setup
- @index = Parent.new("index").dispatch
- @update = Parent.new("update").dispatch
- @delete = Parent.new("delete").dispatch
- @unknown = Parent.new("unknown").dispatch
- end
-
- def test_inherited_excluded
- assert_equal %w(before1 index), @index.log
- end
-
- def test_inherited_not_excluded
- assert_equal %w(before1 before2 update after1), @update.log
- end
-
- def test_partially_excluded
- assert_equal %w(delete after2 after1), @delete.log
- end
-end
-
-class InheritedCallbacksTest2 < Test::Unit::TestCase
- def setup
- @update1 = Child.new("update", :open).dispatch
- @update2 = Child.new("update", :closed).dispatch
- end
-
- def test_crazy_mix_on
- assert_equal %w(before1 update after2 after1), @update1.log
- end
-
- def test_crazy_mix_off
- assert_equal %w(before1 before2 update after2 after1), @update2.log
- end
-end