Sha256: 9d1594e40df2465852d87ddd3931c3858738cb7f8c9d14198a5645b71fd786dc

Contents?: true

Size: 1.93 KB

Versions: 149

Compression:

Stored size: 1.93 KB

Contents

require 'rack/recursive'
require 'rack/mock'

describe Rack::Recursive do
  @app1 = lambda { |env|
    res = Rack::Response.new
    res["X-Path-Info"] = env["PATH_INFO"]
    res["X-Query-String"] = env["QUERY_STRING"]
    res.finish do |inner_res|
      inner_res.write "App1"
    end
  }

  @app2 = lambda { |env|
    Rack::Response.new.finish do |res|
      res.write "App2"
      _, _, body = env['rack.recursive.include'].call(env, "/app1")
      body.each { |b|
        res.write b
      }
    end
  }

  @app3 = lambda { |env|
    raise Rack::ForwardRequest.new("/app1")
  }

  @app4 = lambda { |env|
    raise Rack::ForwardRequest.new("http://example.org/app1/quux?meh")
  }

  should "allow for subrequests" do
    res = Rack::MockRequest.new(Rack::Recursive.new(
                                  Rack::URLMap.new("/app1" => @app1,
                                                   "/app2" => @app2))).
      get("/app2")

    res.should.be.ok
    res.body.should.equal "App2App1"
  end

  should "raise error on requests not below the app" do
    app = Rack::URLMap.new("/app1" => @app1,
                           "/app" => Rack::Recursive.new(
                              Rack::URLMap.new("/1" => @app1,
                                               "/2" => @app2)))

    lambda {
      Rack::MockRequest.new(app).get("/app/2")
    }.should.raise(ArgumentError).
      message.should =~ /can only include below/
  end

  should "support forwarding" do
    app = Rack::Recursive.new(Rack::URLMap.new("/app1" => @app1,
                                               "/app3" => @app3,
                                               "/app4" => @app4))

    res = Rack::MockRequest.new(app).get("/app3")
    res.should.be.ok
    res.body.should.equal "App1"

    res = Rack::MockRequest.new(app).get("/app4")
    res.should.be.ok
    res.body.should.equal "App1"
    res["X-Path-Info"].should.equal "/quux"
    res["X-Query-String"].should.equal "meh"
  end
end

Version data entries

149 entries across 128 versions & 16 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
classiccms-0.7.4 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
classiccms-0.7.3 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
candlepin-api-0.4.0 bundle/ruby/gems/rack-1.3.5/test/spec_recursive.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rack-1.3.5/test/spec_recursive.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/test/spec_recursive.rb
classiccms-0.7.2 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
classiccms-0.7.1 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
classiccms-0.7.0 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
rack-1.3.10 test/spec_recursive.rb
rack-1.2.8 test/spec_recursive.rb
rack-1.3.9 test/spec_recursive.rb
rack-1.2.7 test/spec_recursive.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_recursive.rb
rack-1.3.8 test/spec_recursive.rb
rack-1.3.7 test/spec_recursive.rb
rack-1.2.6 test/spec_recursive.rb
challah-0.9.0 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
classiccms-0.6.9 vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_recursive.rb