Permalink
Browse files

Raise an exception if an initializer is defined without a block

  • Loading branch information...
1 parent dc677f7 commit fa8dfc7d014f6768599077b79a874894e13d317f Carlhuda committed Dec 23, 2009
Showing with 11 additions and 0 deletions.
  1. +1 −0 railties/lib/rails/initializable.rb
  2. +10 −0 railties/test/initializable_test.rb
View
1 railties/lib/rails/initializable.rb
@@ -93,6 +93,7 @@ def initializers_for(scope = :global)
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
10 railties/test/initializable_test.rb
@@ -150,6 +150,16 @@ class Basic < ActiveSupport::TestCase
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

0 comments on commit fa8dfc7

Please sign in to comment.