Sha256: 16e5d7e7099750d0993e55bf145ea837bc4d431892016f7693a1fda475e4426c

Contents?: true

Size: 1.68 KB

Versions: 30

Compression:

Stored size: 1.68 KB

Contents

require_relative "../spec_helper"

describe "cookies plugin" do 
  it "should set cookies on response" do
    app(:cookies) do |r|
      response.set_cookie("foo", "bar")
      response.set_cookie("bar", "baz")
      "Hello"
    end

    header('Set-Cookie').must_equal "foo=bar\nbar=baz"
    body.must_equal 'Hello'
  end

  it "should delete cookies on response" do
    app(:cookies) do |r|
      response.set_cookie("foo", "bar")
      response.delete_cookie("foo")
      "Hello"
    end

    header('Set-Cookie').must_match(/foo=; (max-age=0; )?expires=Thu, 01[ -]Jan[ -]1970 00:00:00 (-0000|GMT)/)
    body.must_equal 'Hello'
  end

  it "should pass default cookie options when setting" do
    app.plugin :cookies, :path => '/foo'
    app.route { response.set_cookie("foo", "bar") }
    header('Set-Cookie').must_equal "foo=bar; path=/foo"

    app.route { response.set_cookie("foo", :value=>"bar", :path=>'/baz') }
    header('Set-Cookie').must_equal "foo=bar; path=/baz"
  end

  it "should pass default cookie options when deleting" do
    app.plugin :cookies, :domain => 'example.com'
    app.route { response.delete_cookie("foo") }
    header('Set-Cookie').must_match(/foo=; domain=example.com; (max-age=0; )?expires=Thu, 01[ -]Jan[ -]1970 00:00:00 (-0000|GMT)/)

    app.route { response.delete_cookie("foo", :domain=>'bar.com') }
    header('Set-Cookie').must_match(/foo=; domain=bar.com; (max-age=0; )?expires=Thu, 01[ -]Jan[ -]1970 00:00:00 (-0000|GMT)/)
  end

  it "should not override existing default cookie options" do
    app.plugin :cookies, :path => '/foo'
    app.plugin :cookies
    app.route { response.set_cookie("foo", "bar") }

    header('Set-Cookie').must_equal "foo=bar; path=/foo"
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
roda-3.9.0 spec/plugin/cookies_spec.rb
roda-3.8.0 spec/plugin/cookies_spec.rb
roda-3.7.0 spec/plugin/cookies_spec.rb
roda-3.6.0 spec/plugin/cookies_spec.rb
roda-3.5.0 spec/plugin/cookies_spec.rb
roda-3.4.0 spec/plugin/cookies_spec.rb
roda-3.3.0 spec/plugin/cookies_spec.rb
roda-3.2.0 spec/plugin/cookies_spec.rb
roda-3.1.0 spec/plugin/cookies_spec.rb
roda-3.0.0 spec/plugin/cookies_spec.rb