Sha256: 7a0ad7b3eb8a61dc287ae5ad1ca889f4f6fa4b1225a801019bfd6e438653cb04

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
require "usher"

describe "Rack interface extensions for Usher::Route" do
  before(:each) do
    @route_set = Usher::Interface.for(:rack)
    @app = MockApp.new("Hello World!")
    @env = Rack::MockRequest.env_for("/index.html")
  end

  describe "basic functinality" do
    it "should set redirect headers" do
      @route_set.get("/index.html").redirect("/")
      raw_response = @route_set.call(@env)
      response = Rack::MockResponse.new(*raw_response)
      response.should be_redirect
    end

    it "should redirect '/index.html' to '/'" do
      @route_set.get("/index.html").redirect("/")
      status, headers, body = @route_set.call(@env)
      headers["Location"].should eql("/")
    end
  end

  describe "chaining" do
    it "should be chainable" do
      @route_set.get("/index.html").redirect("/").name(:root)
      url = @route_set.router.generator.generate(:root)
      url.should eql("/index.html")
    end

    it "should not influence actual invoking" do
      @route_set.get("/index.html").redirect("/").name(:root)
      @route_set.call(@env)
    end
  end

  describe "custom status" do
    it "should enable to set custom HTTP status" do
      @route_set.get("/index.html").redirect("/", 303)
      status, headers, body = @route_set.call(@env)
      status.should eql(303)
    end

    it "should raise an exception if given HTTP code isn't a redirection" do
      lambda { @route_set.get("/index.html").redirect("/", 200) }.should raise_error(ArgumentError)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
usher-0.7.4 spec/private/rack/route_spec.rb
usher-0.7.3 spec/private/rack/route_spec.rb
usher-0.7.2 spec/private/rack/route_spec.rb
usher-0.7.1 spec/private/rack/route_spec.rb
usher-0.7.0 spec/private/rack/route_spec.rb
usher-0.6.8 spec/private/rack/route_spec.rb
usher-0.6.7 spec/private/rack/route_spec.rb
usher-0.6.6 spec/private/rack/route_spec.rb
usher-0.6.5 spec/private/rack/route_spec.rb
usher-0.6.4 spec/private/rack/route_spec.rb
usher-0.6.3 spec/private/rack/route_spec.rb
usher-0.6.2 spec/private/rack/route_spec.rb
usher-0.6.1 spec/private/rack/route_spec.rb
usher-0.6.0 spec/private/rack/route_spec.rb
usher-0.5.13 spec/private/rack/route_spec.rb
usher-0.5.12 spec/private/rack/route_spec.rb