Sha256: cfdb8ea545e02aa84d44a68798515eec9e79cec3b2db380bed8f73b6bff97e9b

Contents?: true

Size: 1.67 KB

Versions: 23

Compression:

Stored size: 1.67 KB

Contents

require 'rack/cascade'
require 'rack/file'
require 'rack/urlmap'
require 'rack/mock'

describe Rack::Cascade do
  docroot = File.expand_path(File.dirname(__FILE__))
  app1 = Rack::File.new(docroot)

  app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" })

  app3 = Rack::URLMap.new("/foo" => lambda { |env|
                            [200, { "Content-Type" => "text/plain"}, [""]]})

  should "dispatch onward on 404 by default" do
    cascade = Rack::Cascade.new([app1, app2, app3])
    Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok
    Rack::MockRequest.new(cascade).get("/foo").should.be.ok
    Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden
  end

  should "dispatch onward on whatever is passed" do
    cascade = Rack::Cascade.new([app1, app2, app3], [404, 403])
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found
  end

  should "return 404 if empty" do
    Rack::MockRequest.new(Rack::Cascade.new([])).get('/').should.be.not_found
  end

  should "append new app" do
    cascade = Rack::Cascade.new([], [404, 403])
    Rack::MockRequest.new(cascade).get('/').should.be.not_found
    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

Version data entries

23 entries across 21 versions & 4 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/gems/rack-1.3.5/test/spec_cascade.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/test/spec_cascade.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rack-1.3.5/test/spec_cascade.rb
rack-1.2.8 test/spec_cascade.rb
rack-1.2.7 test/spec_cascade.rb
rack-1.2.6 test/spec_cascade.rb
rack-1.3.6 test/spec_cascade.rb
rack-1.2.5 test/spec_cascade.rb
rack-1.3.5 test/spec_cascade.rb
rack-1.3.4 test/spec_cascade.rb
rack-1.2.4 test/spec_cascade.rb
rack-1.3.3 test/spec_cascade.rb
rack-1.3.2 test/spec_cascade.rb
rack-1.3.1 test/spec_cascade.rb
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/rack-1.3.0/test/spec_cascade.rb
rack-1.2.3 test/spec_cascade.rb
rack-1.3.0 test/spec_cascade.rb
rack-1.3.0.beta2 test/spec_cascade.rb
rack-1.3.0.beta test/spec_cascade.rb
rack-1.2.2 test/spec_cascade.rb