aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-04-27 18:16:55 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-01 17:31:01 -0700
commit34509777fd375e5bc529f21ca66cf63263c2cf64 (patch)
treeb553841b1ac6777eb06a864e44bacd7ed2966772 /activesupport
parent3be3470fab788856b4559742434f195cc6b1009a (diff)
downloadrails-34509777fd375e5bc529f21ca66cf63263c2cf64.tar.gz
rails-34509777fd375e5bc529f21ca66cf63263c2cf64.tar.bz2
rails-34509777fd375e5bc529f21ca66cf63263c2cf64.zip
Makes new callbacks support keys with special characters
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/new_callbacks.rb1
-rw-r--r--activesupport/test/new_callbacks_test.rb28
2 files changed, 29 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb
index 7a48dbac04..8a91e1c674 100644
--- a/activesupport/lib/active_support/new_callbacks.rb
+++ b/activesupport/lib/active_support/new_callbacks.rb
@@ -356,6 +356,7 @@ module ActiveSupport
str = <<-RUBY_EVAL
def _run_#{symbol}_callbacks(key = nil)
if key
+ key = key.hash.to_s.gsub(/-/, '_')
name = "_run__\#{self.class.name.split("::").last}__#{symbol}__\#{key}__callbacks"
if respond_to?(name)
diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb
index abe7790ebf..8c887e1bf1 100644
--- a/activesupport/test/new_callbacks_test.rb
+++ b/activesupport/test/new_callbacks_test.rb
@@ -255,6 +255,26 @@ module NewCallbacksTest
end
end
+ class HyphenatedCallbacks
+ include ActiveSupport::NewCallbacks
+ define_callbacks :save
+ attr_reader :stuff
+
+ save_callback :before, :omg, :per_key => {:if => :yes}
+
+ def yes() true end
+
+ def omg
+ @stuff = "OMG"
+ end
+
+ def save
+ _run_save_callbacks("hyphen-ated") do
+ @stuff
+ end
+ end
+ end
+
class AroundCallbacksTest < Test::Unit::TestCase
def test_save_around
around = AroundPerson.new
@@ -381,4 +401,12 @@ module NewCallbacksTest
assert_equal ["first", "second", "third", "second", "first"], terminator.history
end
end
+
+ class HyphenatedKeyTest < Test::Unit::TestCase
+ def test_save
+ obj = HyphenatedCallbacks.new
+ obj.save
+ assert_equal obj.stuff, "OMG"
+ end
+ end
end