diff options
-rw-r--r-- | railties/test/new_initializer_test.rb | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb index 166e7e613f..ffa10060ce 100644 --- a/railties/test/new_initializer_test.rb +++ b/railties/test/new_initializer_test.rb @@ -11,20 +11,15 @@ module Rails end def add(name, options = {}, &block) - if other = options[:before] || options[:after] and !@names[other] - raise Error, "The #{other.inspect} initializer does not exist" + # If :before or :after is specified, set the index to the right spot + if other = options[:before] || options[:after] + raise Error, "The #{other.inspect} initializer does not exist" unless @names[other] + index = @initializers.index(@names[other]) + index += 1 if options[:after] end Class.new(Initializer, &block).new.tap do |initializer| - index = if options[:before] - @initializers.index(@names[other]) - elsif options[:after] - @initializers.index(@names[other]) + 1 - else - -1 - end - - @initializers.insert(index, initializer) + @initializers.insert(index || -1, initializer) @names[name] = initializer end end |