Permalink
Browse files

Addition of #add, #<<, and #include? to Cascade, allowing iterative a…

…ddition of apps

darcs-hash:20080311063124-f4dbf-23c5cce18626c600a4a78d9d2d4b41ae53c691f7.gz
  • Loading branch information...
1 parent cbdf034 commit 8dace607d0063cbc2dd217421713ddc00b03a574 @scytrin scytrin committed Mar 11, 2008
Showing with 25 additions and 0 deletions.
  1. +10 −0 lib/rack/cascade.rb
  2. +15 −0 test/spec_rack_cascade.rb
View
10 lib/rack/cascade.rb
@@ -22,5 +22,15 @@ def call(env)
}
[status, headers, body]
end
+
+ def add app
+ @apps << app
+ end
+
+ def include? app
+ @apps.include? app
+ end
+
+ alias_method :<<, :add
end
end
View
15 test/spec_rack_cascade.rb
@@ -32,4 +32,19 @@
lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }.
should.raise(ArgumentError)
end
+
+ specify "should append new app" do
+ cascade = Rack::Cascade.new([], [404, 403])
+ lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }.
+ should.raise(ArgumentError)
+ cascade << app2
+ Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found
+ Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found
+ cascade << app1
+ Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok
+ Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden
+ Rack::MockRequest.new(cascade).get('/foo').should.be.not_found
+ cascade << app3
+ Rack::MockRequest.new(cascade).get('/foo').should.be.ok
+ end
end

0 comments on commit 8dace60

Please sign in to comment.