1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Expose the session model backing CGI::Session

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2696 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2005-10-20 21:59:48 +00:00
parent 5f0b9369cc
commit 22d9bad8a0
5 changed files with 36 additions and 9 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Expose the session model backing CGI::Session
* Abbreviate RAILS_ROOT in traces

View file

@ -4,6 +4,7 @@ require 'action_controller/routing'
require 'action_controller/code_generation'
require 'action_controller/url_rewriter'
require 'drb'
require 'set'
module ActionController #:nodoc:
class ActionControllerError < StandardError #:nodoc:
@ -846,8 +847,7 @@ module ActionController #:nodoc:
end
def self.action_methods
#puts "action method: #{public_instance_methods.inspect}"
@action_methods ||= (public_instance_methods - hidden_actions).inject({}) { |h, k| h[k] = true; h }
@action_methods ||= Set.new(public_instance_methods - hidden_actions)
end
def add_variables_to_assigns

View file

@ -5,6 +5,16 @@ require 'base64'
class CGI
class Session
# Return this session's underlying Session model. Useful for the DB-backed session stores.
def model
@dbman.model rescue nil
end
# Proxy missing methods to the underlying Session model.
def method_missing(method, *args, &block)
if model then model.send(method, *args, &block) else super end
end
# A session store backed by an Active Record class.
#
# A default class is provided, but any object duck-typing to an Active
@ -277,6 +287,11 @@ class CGI
end
end
# Access the underlying session model.
def model
@session
end
# Restore session state. The session model handles unmarshaling.
def restore
if @session

View file

@ -53,7 +53,6 @@ module CommonActiveRecordStoreTests
@new_session.close
end
end
end
class ActiveRecordStoreTest < Test::Unit::TestCase
@ -73,13 +72,17 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
@new_session['foo'] = 'bar'
end
def test_model_attribute
assert_kind_of CGI::Session::ActiveRecordStore::Session, @new_session.model
assert_equal @new_session.model.data, @new_session.data
end
def teardown
session_class.drop_table!
end
end
class ColumnLimitTest < Test::Unit::TestCase
def setup
@session_class = CGI::Session::ActiveRecordStore::Session
@session_class.create_table!
@ -97,10 +100,8 @@ class ColumnLimitTest < Test::Unit::TestCase
s.data
assert_raises(ActionController::SessionOverflowError) { s.save }
end
end
class DeprecatedActiveRecordStoreTest < ActiveRecordStoreTest
def setup
session_class.connection.execute 'create table old_sessions (id integer primary key, sessid text unique, data text)'
@ -128,6 +129,11 @@ class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
end
@session_class
end
def test_model_attribute
assert_kind_of CGI::Session::ActiveRecordStore::SqlBypass, @new_session.model
assert_equal @new_session.model.data, @new_session.data
end
end

View file

@ -67,7 +67,11 @@ class ControllerInstanceTests < Test::Unit::TestCase
end
def test_action_methods
@empty_controllers.each {|c| assert_equal({}, c.send(:action_methods), "#{c.class.controller_path} should be empty!")}
@non_empty_controllers.each {|c| assert_equal({"public_action"=>true}, c.send(:action_methods), "#{c.class.controller_path} should not be empty!")}
@empty_controllers.each do |c|
assert_equal Set.new, c.send(:action_methods), "#{c.class.controller_path} should be empty!"
end
@non_empty_controllers.each do |c|
assert_equal Set.new('public_action'), c.send(:action_methods), "#{c.class.controller_path} should not be empty!"
end
end
end