Sha256: 1f2bfbf92f8492ae173188585629236f05049187bd83ce4fd5fc7238c659ae1f

Contents?: true

Size: 1.86 KB

Versions: 121

Compression:

Stored size: 1.86 KB

Contents

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

describe Rack::Cascade do
  def cascade(*args)
    Rack::Lint.new Rack::Cascade.new(*args)
  end
  
  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 and 405 by default" do
    cascade = cascade([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/../..").should.be.client_error

    # Put is not allowed by Rack::File so it'll 405.
    Rack::MockRequest.new(cascade).put("/foo").should.be.ok
  end

  should "dispatch onward on whatever is passed" do
    cascade = cascade([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(cascade([])).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/../..').should.be.client_error
    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

121 entries across 102 versions & 13 rubygems

Version Path
classiccms-0.5.2 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.5.1 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.5.0 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.4.2 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.4.1 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.4.0 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.3.9 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
challah-0.6.2 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
initforthe-cookies-0.0.1 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_cascade.rb
classiccms-0.3.8 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb
challah-0.6.1 vendor/bundle/gems/rack-1.4.1/test/spec_cascade.rb