Sha256: 9569a3657791ab61aefd3c8cbf3537452660e080190ce79158377977ccccf411

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

require "spec_helper"
require "shamu/rack"

describe Shamu::Rack::Cookies do
  let( :headers ) { {} }
  let( :env )     { {} }
  let( :cookies ) { Shamu::Rack::Cookies.new( env ) }

  it "sets a cookie" do
    cookies.set( :id, "123" )
    expect( cookies.get( "id" ) ).to eq "123"
  end

  it "gets a cookie" do
    env[ "HTTP_COOKIE" ] = "remember_me=true; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000"
    expect( cookies.get( "remember_me" ) ).to eq "true"
  end

  it "overwrites existing cookie" do
    env[ "HTTP_COOKIE" ] = "favorite=batman"
    cookies.set( "favorite", "superman" )

    expect( cookies.get( "favorite" ) ).to eq "superman"
  end

  describe "#apply" do
    it "adds new cookies" do
      cookies.set( "name", "phallguy" )
      cookies.apply!( headers )

      expect( headers[ "Set-Cookie" ] ).to match /phallguy/
    end

    it "removes old cookies" do
      env[ "HTTP_COOKIE" ] = "remember_me=true"

      cookies.delete( "remember_me" )
      cookies.apply!( headers )

      expect( headers[ "Set-Cookie" ] ).to match /remember_me=;/
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.21 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.20 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.19 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.18 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.17 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.15 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.14 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.13 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.11 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.9 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.8 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.7 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.5 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.4 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.3 spec/lib/shamu/rack/cookies_spec.rb
shamu-0.0.2 spec/lib/shamu/rack/cookies_spec.rb