Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rack/session/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _exists?(sid)
end

def _record(sid)
@pool.filter('sid = ?', sid)
@pool.where(sid: sid)
end
end
end
Expand Down
99 changes: 0 additions & 99 deletions lib/rack/session/sequel_org.rb

This file was deleted.

88 changes: 43 additions & 45 deletions spec/spec_session_sequel.rb → spec/session_sequel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,23 @@
it "creates a new cookie" do
pool = Rack::Session::Sequel.new(incrementor)
res = Rack::MockRequest.new(pool).get("/")
res["Set-Cookie"].should.match session_match
res.body.should.equal '{"counter"=>1}'
expect(res["Set-Cookie"]).to match session_match
expect(res.body).to eq '{"counter"=>1}'
end

it "determines session from a cookie" do
pool = Rack::Session::Sequel.new(incrementor)
req = Rack::MockRequest.new(pool)
cookie = req.get("/")["Set-Cookie"]
req.get("/", "HTTP_COOKIE" => cookie).
body.should.equal '{"counter"=>2}'
req.get("/", "HTTP_COOKIE" => cookie).
body.should.equal '{"counter"=>3}'
expect(req.get("/", "HTTP_COOKIE" => cookie).body).to eq '{"counter"=>2}'
expect(req.get("/", "HTTP_COOKIE" => cookie).body).to eq '{"counter"=>3}'
end

it "survives nonexistant cookies" do
pool = Rack::Session::Sequel.new(incrementor)
res = Rack::MockRequest.new(pool).
get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel")
res.body.should.equal '{"counter"=>1}'
expect(res.body).to eq '{"counter"=>1}'
end

it "does not send the same session id if it did not change" do
Expand All @@ -66,18 +64,18 @@

res0 = req.get("/")
cookie = res0["Set-Cookie"][session_match]
res0.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 1
expect(res0.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 1

res1 = req.get("/", "HTTP_COOKIE" => cookie)
res1["Set-Cookie"].should.be.nil
res1.body.should.equal '{"counter"=>2}'
pool.pool.count.should.equal 1
expect(res1["Set-Cookie"]).to be_nil
expect(res1.body).to eq '{"counter"=>2}'
expect(pool.pool.count).to eq 1

res2 = req.get("/", "HTTP_COOKIE" => cookie)
res2["Set-Cookie"].should.be.nil
res2.body.should.equal '{"counter"=>3}'
pool.pool.count.should.equal 1
expect(res2["Set-Cookie"]).to be_nil
expect(res2.body).to eq '{"counter"=>3}'
expect(pool.pool.count).to eq 1
end

it "deletes cookies with :drop option" do
Expand All @@ -88,18 +86,18 @@

res1 = req.get("/")
session = (cookie = res1["Set-Cookie"])[session_match]
res1.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 1
expect(res1.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 1

res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
res2["Set-Cookie"].should.be.nil
res2.body.should.equal '{"counter"=>2}'
pool.pool.count.should.equal 0
expect(res2["Set-Cookie"]).to be_nil
expect(res2.body).to eq '{"counter"=>2}'
expect(pool.pool.count).to eq 0

res3 = req.get("/", "HTTP_COOKIE" => cookie)
res3["Set-Cookie"][session_match].should.not.equal session
res3.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 1
expect(res3["Set-Cookie"][session_match]).to_not eq session
expect(res3.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 1
end

it "provides new session id with :renew option" do
Expand All @@ -110,23 +108,23 @@

res1 = req.get("/")
session = (cookie = res1["Set-Cookie"])[session_match]
res1.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 1
expect(res1.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 1

res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
new_cookie = res2["Set-Cookie"]
new_session = new_cookie[session_match]
new_session.should.not.equal session
res2.body.should.equal '{"counter"=>2}'
pool.pool.count.should.equal 1
expect(new_session).to_not eq session
expect(res2.body).to eq '{"counter"=>2}'
expect(pool.pool.count).to eq 1

res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
res3.body.should.equal '{"counter"=>3}'
pool.pool.count.should.equal 1
expect(res3.body).to eq '{"counter"=>3}'
expect(pool.pool.count).to eq 1

res4 = req.get("/", "HTTP_COOKIE" => cookie)
res4.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 2
expect(res4.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 2
end

it "omits cookie with :defer option" do
Expand All @@ -135,15 +133,15 @@
dreq = Rack::MockRequest.new(defer)

res1 = dreq.get("/")
res1["Set-Cookie"].should.equal nil
res1.body.should.equal '{"counter"=>1}'
pool.pool.count.should.equal 1
expect(res1["Set-Cookie"]).to eq nil
expect(res1.body).to eq '{"counter"=>1}'
expect(pool.pool.count).to eq 1
end

# anyone know how to do this better?
it "should merge sessions when multithreaded" do
unless $DEBUG
1.should.equal 1
expect(1).to eq 1
next
end

Expand All @@ -152,7 +150,7 @@
req = Rack::MockRequest.new(pool)

res = req.get('/')
res.body.should.equal '{"counter"=>1}'
expect(res.body).to eq '{"counter"=>1}'
cookie = res["Set-Cookie"]
sess_id = cookie[/#{pool.key}=([^,;]+)/,1]

Expand All @@ -172,36 +170,36 @@
end
end.reverse.map{|t| t.run.join.value }
r.each do |resp|
resp['Set-Cookie'].should.equal cookie
resp.body.should.include '"counter"=>2'
expect(resp['Set-Cookie']).to eq cookie
expect(resp.body).to include '"counter"=>2'
end

session = pool.pool[sess_id]
session.count.should.equal tnum+1 # counter
session['counter'].should.equal 2 # meeeh
expect(session.count).to eq tnum+1 # counter
expect(session['counter']).to eq 2 # meeeh
end

it "does not return a cookie if cookie was not read/written" do
app = Rack::Session::Sequel.new(nothing)
res = Rack::MockRequest.new(app).get("/")
res["Set-Cookie"].should.be.nil
expect(res["Set-Cookie"]).to be_nil
end

it "does not return a cookie if cookie was not written (only read)" do
app = Rack::Session::Sequel.new(session_id)
res = Rack::MockRequest.new(app).get("/")
res["Set-Cookie"].should.be.nil
expect(res["Set-Cookie"]).to be_nil
end

it "returns even if not read/written if :expire_after is set" do
app = Rack::Session::Sequel.new(nothing, :expire_after => 3600)
res = Rack::MockRequest.new(app).get("/", 'rack.session' => {'not' => 'empty'})
res["Set-Cookie"].should.not.be.nil
expect(res["Set-Cookie"]).to_not be_nil
end

it "returns no cookie if no data was written and no session was created previously, even if :expire_after is set" do
app = Rack::Session::Sequel.new(nothing, :expire_after => 3600)
res = Rack::MockRequest.new(app).get("/")
res["Set-Cookie"].should.be.nil
expect(res["Set-Cookie"]).to be_nil
end
end