Navigation Menu

Skip to content

Commit

Permalink
Expose the session model backing CGI::Session
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2696 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Oct 20, 2005
1 parent 5f0b936 commit 22d9bad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Expose the session model backing CGI::Session

* Abbreviate RAILS_ROOT in traces


Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions actionpack/lib/action_controller/session/active_record_store.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions actionpack/test/controller/active_record_store_test.rb
Expand Up @@ -53,7 +53,6 @@ def test_tolerates_close_close
@new_session.close
end
end

end

class ActiveRecordStoreTest < Test::Unit::TestCase
Expand All @@ -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!
Expand All @@ -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)'
Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions actionpack/test/controller/base_test.rb
Expand Up @@ -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.