Raise an exception if an initializer is defined without a block

This commit is contained in:
Carlhuda
2009-12-23 13:45:55 -08:00
parent dc677f7665
commit fa8dfc7d01
2 changed files with 11 additions and 0 deletions

View File

@@ -93,6 +93,7 @@ module Rails
end
def initializer(name, opts = {}, &blk)
raise ArgumentError, "A block must be passed when defining an initializer" unless blk
@initializers ||= []
@initializers << Initializer.new(name, nil, opts, &blk)
end

View File

@@ -150,6 +150,16 @@ module InitializableTests
Word.run_initializers
assert_equal "bird", $word
end
test "creating initializer without a block raises an error" do
assert_raise(ArgumentError) do
Class.new do
include Rails::Initializable
initializer :foo
end
end
end
end
class BeforeAfter < ActiveSupport::TestCase