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.28.0 spec/plugin/cookies_spec.rb
roda-3.27.0 spec/plugin/cookies_spec.rb
roda-3.26.0 spec/plugin/cookies_spec.rb
roda-3.25.0 spec/plugin/cookies_spec.rb
roda-3.24.0 spec/plugin/cookies_spec.rb
roda-3.23.0 spec/plugin/cookies_spec.rb
roda-3.22.0 spec/plugin/cookies_spec.rb
roda-3.21.0 spec/plugin/cookies_spec.rb
roda-3.20.0 spec/plugin/cookies_spec.rb
roda-3.19.0 spec/plugin/cookies_spec.rb
roda-3.18.0 spec/plugin/cookies_spec.rb
roda-3.17.0 spec/plugin/cookies_spec.rb
roda-3.16.0 spec/plugin/cookies_spec.rb
roda-3.15.0 spec/plugin/cookies_spec.rb
roda-3.14.1 spec/plugin/cookies_spec.rb
roda-3.14.0 spec/plugin/cookies_spec.rb
roda-3.13.0 spec/plugin/cookies_spec.rb
roda-3.12.0 spec/plugin/cookies_spec.rb
roda-3.11.0 spec/plugin/cookies_spec.rb
roda-3.10.0 spec/plugin/cookies_spec.rb