Sha256: 6edcff6dd77051724835beaab5167ce5b387b729cdd71851392878c57aa7816e

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

require "spec_helper"

describe Shamu::Sessions::CookieStore do

  hunt( :cookies, Shamu::Rack::Cookies )
  let( :store ) { scorpion.new Shamu::Sessions::CookieStore }

  it "stores signed cookies" do
    expect( cookies ).to receive( :set ).with( "setting", hash_including( value: /[0-9a-f]{40}\$example/ ) )
    expect( store ).to receive( :hash_value ).and_call_original

    store.set( "setting", "example" )
  end

  it "reads signed cookies" do
    hashed = store.send( :hash_value, "example" )
    expect( cookies ).to receive( :key? ).with( "setting" ).and_return true
    expect( cookies ).to receive( :get ).with( "setting" ).and_return hashed
    expect( store ).to receive( :verify_hash ).and_call_original

    expect( store.fetch( "setting" ) ).to eq "example"
  end

  it "yields if cookie does not exist" do
    expect( cookies ).to receive( :key? ).with( "setting" ).and_return false

    expect do |b|
      store.fetch( "setting", &b )
    end.to yield_control
  end

  it "ignores unsigned cookies" do
    expect( cookies ).to receive( :key? ).with( "setting" ).and_return true
    expect( cookies ).to receive( :get ).with( "setting" ).and_return "example"
    expect( store ).to receive( :verify_hash ).and_call_original

    expect( store.fetch( "setting" ) ).to eq nil
  end

  it "deletes a cookie" do
    expect( cookies ).to receive( :delete )
    store.delete( "setting" )
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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