Sha256: e897a1dd03f5be476e859a325e895cd1091c78364972a11c059ed33b58726fbb

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

require "spec_helper"

describe Pliny::Middleware::CORS do
  def app
    Rack::Builder.new do
      use Rack::Lint
      use Pliny::Middleware::CORS
      run Sinatra.new {
        get "/" do
          "hi"
        end
      }
    end
  end

  it "doesn't do anything when the Origin header is not present" do
    get "/"
    assert_equal 200, last_response.status
    assert_equal "hi", last_response.body
    assert_nil last_response.headers["Access-Control-Allow-Origin"]
  end

  it "intercepts OPTION requests to render a stub (preflight request)" do
    header "Origin", "http://localhost"
    options "/"
    assert_equal 200, last_response.status
    assert_equal "", last_response.body
    assert_equal "GET, POST, PUT, PATCH, DELETE, OPTIONS",
      last_response.headers["Access-Control-Allow-Methods"]
    assert_equal "http://localhost",
      last_response.headers["Access-Control-Allow-Origin"]
  end

  it "delegates other calls, adding the CORS headers to the response" do
    header "Origin", "http://localhost"
    get "/"
    assert_equal 200, last_response.status
    assert_equal "hi", last_response.body
    assert_equal "http://localhost",
      last_response.headers["Access-Control-Allow-Origin"]
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pliny-0.26.0 spec/middleware/cors_spec.rb
pliny-0.25.1 spec/middleware/cors_spec.rb
pliny-0.25.0 spec/middleware/cors_spec.rb
pliny-0.24.0 spec/middleware/cors_spec.rb
pliny-0.23.0 spec/middleware/cors_spec.rb
pliny-0.22.0 spec/middleware/cors_spec.rb
pliny-0.21.0 spec/middleware/cors_spec.rb
pliny-0.20.2 spec/middleware/cors_spec.rb
pliny-0.20.1 spec/middleware/cors_spec.rb
pliny-0.20.0 spec/middleware/cors_spec.rb