Permalink
Browse files

Expose the session model backing CGI::Session

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2696 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5f0b936 commit 22d9bad8a038eef751e1270f204211cca3c8af18 @jeremy jeremy committed Oct 20, 2005
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Expose the session model backing CGI::Session
+
* Abbreviate RAILS_ROOT in traces
View
4 actionpack/lib/action_controller/base.rb
@@ -4,6 +4,7 @@
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 @@ def action_methods
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
15 actionpack/lib/action_controller/session/active_record_store.rb
@@ -5,6 +5,16 @@
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 @@ def initialize(session, option = nil)
end
end
+ # Access the underlying session model.
+ def model
+ @session
+ end
+
# Restore session state. The session model handles unmarshaling.
def restore
if @session
View
16 actionpack/test/controller/active_record_store_test.rb
@@ -53,7 +53,6 @@ def test_tolerates_close_close
@new_session.close
end
end
-
end
class ActiveRecordStoreTest < Test::Unit::TestCase
@@ -73,13 +72,17 @@ def setup
@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 @@ def test_protection_from_data_larger_than_column
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,12 +129,17 @@ def session_class
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
# End of safety net.
rescue Object => e
- $stderr.puts "Skipping CGI::Session::ActiveRecordStore tests: #{e}"
+ $stderr.puts "Skipping CGI::Session::ActiveRecordStore tests: #{e}"
#$stderr.puts " #{e.backtrace.join("\n ")}"
end
end
View
8 actionpack/test/controller/base_test.rb
@@ -67,7 +67,11 @@ def setup
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

0 comments on commit 22d9bad

Please sign in to comment.