Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Trying to make session storage working, including patch from http://g…

  • Loading branch information...
commit b86487ff237f2679a75ac25ef5d61ec3a9c00dfc 1 parent 274af85
@pk authored
View
18 lib/merb/session/sequel_session.rb
@@ -57,10 +57,15 @@ def retrieve_session(session_id)
# session_id<String>:: ID of the session to set.
# data<ContainerSession>:: The session to set.
def store_session(session_id, data)
- if item = find(:session_id => session_id)
- item.update(:data => data)
- else
- create(:session_id => session_id, :data => data, :created_at => Time.now)
+ begin
+ if item = find(:session_id => session_id)
+ item.update(:data => data)
+ else
+ item = self.new(:session_id => session_id, :data => data, :created_at => Time.now)
+ item.save
+ end
+ rescue => e
+ Merb.logger.error("#{e.message} when trying to save #{data}")
end
end
@@ -86,12 +91,13 @@ def data_column_size_limit
# Lazy-unserialize session state.
def data
- @data ||= (@values[:data] ? Marshal.load(@values[:data]) : {})
+ data = (@values[:data] ? Marshal.load(@values[:data]) : {}) if @data.nil?
+ @data
end
# Virtual attribute writer - override.
def data=(hsh)
- @data = hsh if hsh.is_a?(Hash)
+ super(hsh) if hsh.is_a?(Hash)
end
# Has the session been loaded yet?
View
4 spec/merb_sequel_session_spec.rb
@@ -14,10 +14,10 @@
end
it "should persist values" do
- response = request(url(:controller => :spec_controller, :action => :set))
+ response = request(url(:set))
response.should be_successful
response.body.should == 'value'
- response = request(url(:controller => :spec_controller, :action => :get))
+ response = request(url(:get))
response.should be_successful
response.body.should == 'value'
end
View
5 spec/spec_controller.rb
@@ -1,9 +1,10 @@
class SpecController < Merb::Controller
def set
session[:key] = 'value'
+ render session[:key].to_s
end
def get
- session[:key]
+ render session[:key].to_s
end
-end
+end
View
9 spec/spec_helper.rb
@@ -21,9 +21,10 @@
config.include Merb::Test::RequestHelper
end
-Merb::Router.prepare do
- default_routes
-end
-
require File.join( File.dirname(__FILE__), 'spec_model')
require File.join( File.dirname(__FILE__), 'spec_controller')
+
+Merb::Router.prepare do
+ match('/set').to(:controller => :spec_controller, :action => :set).name(:set)
+ match('/get').to(:controller => :spec_controller, :action => :get).name(:get)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.