diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-21 15:17:04 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-21 15:17:04 +0200 |
commit | 9dfe9fa693c98a828dae6ad96eb9798bbdea7d81 (patch) | |
tree | 68cc06520c8fb39f5d0866020104dfacfd88825e /actionpack/lib/action_dispatch | |
parent | 71312443133c6bbcc518d594789f19a213369f2a (diff) | |
download | rails-9dfe9fa693c98a828dae6ad96eb9798bbdea7d81.tar.gz rails-9dfe9fa693c98a828dae6ad96eb9798bbdea7d81.tar.bz2 rails-9dfe9fa693c98a828dae6ad96eb9798bbdea7d81.zip |
Ensure insert_before in middleware stack raises a meaningful error message [#3679 state:resolved]
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/stack.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 4618f3befc..41078eced7 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -46,7 +46,7 @@ module ActionDispatch end def insert(index, *args, &block) - index = self.index(index) unless index.is_a?(Integer) + index = assert_index(index, :before) middleware = self.class::Middleware.new(*args, &block) super(index, middleware) end @@ -54,9 +54,8 @@ module ActionDispatch alias_method :insert_before, :insert def insert_after(index, *args, &block) - i = index.is_a?(Integer) ? index : self.index(index) - raise "No such middleware to insert after: #{index.inspect}" unless i - insert(i + 1, *args, &block) + index = assert_index(index, :after) + insert(index + 1, *args, &block) end def swap(target, *args, &block) @@ -79,5 +78,13 @@ module ActionDispatch raise "MiddlewareStack#build requires an app" unless app reverse.inject(app) { |a, e| e.build(a) } end + + protected + + def assert_index(index, where) + i = index.is_a?(Integer) ? index : self.index(index) + raise "No such middleware to insert #{where}: #{index.inspect}" unless i + i + end end end |