1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Makes new callbacks support keys with special characters

This commit is contained in:
Yehuda Katz + Carl Lerche 2009-04-27 18:16:55 -07:00
parent 3be3470fab
commit 34509777fd
2 changed files with 29 additions and 0 deletions

View file

@ -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)

View file

@ -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