Sha256: 75e3585bac149186fda3074d748f919f09cc4c80752607671ce5a1a5fa46c5ec

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 KB

Contents

require "test_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_equal 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

11 entries across 11 versions & 1 rubygems

Version Path
pliny-0.4.0 test/middleware/cors_test.rb
pliny-0.3.0 test/middleware/cors_test.rb
pliny-0.2.1 test/middleware/cors_test.rb
pliny-0.2.0 test/middleware/cors_test.rb
pliny-0.1.0 test/middleware/cors_test.rb
pliny-0.0.4 test/middleware/cors_test.rb
pliny-0.0.3 test/middleware/cors_test.rb
pliny-0.0.1 test/middleware/cors_test.rb
pliny-0.0.1.pre3 test/middleware/cors_test.rb
pliny-0.0.1.pre2 test/middleware/cors_test.rb
pliny-0.0.1.pre test/middleware/cors_test.rb