Skip to content
This repository
Browse code

Raise an exception if an initializer is defined without a block

  • Loading branch information...
commit fa8dfc7d014f6768599077b79a874894e13d317f 1 parent dc677f7
Carlhuda authored
1  railties/lib/rails/initializable.rb
@@ -93,6 +93,7 @@ def initializers_for(scope = :global)
93 93 end
94 94
95 95 def initializer(name, opts = {}, &blk)
  96 + raise ArgumentError, "A block must be passed when defining an initializer" unless blk
96 97 @initializers ||= []
97 98 @initializers << Initializer.new(name, nil, opts, &blk)
98 99 end
10 railties/test/initializable_test.rb
@@ -150,6 +150,16 @@ class Basic < ActiveSupport::TestCase
150 150 Word.run_initializers
151 151 assert_equal "bird", $word
152 152 end
  153 +
  154 + test "creating initializer without a block raises an error" do
  155 + assert_raise(ArgumentError) do
  156 + Class.new do
  157 + include Rails::Initializable
  158 +
  159 + initializer :foo
  160 + end
  161 + end
  162 + end
153 163 end
154 164
155 165 class BeforeAfter < ActiveSupport::TestCase

0 comments on commit fa8dfc7

Please sign in to comment.
Something went wrong with that request. Please try again.