Permalink
Browse files

r2836@asus: jeremy | 2005-07-05 00:33:12 -0700

 Test sessid backward compatibility.  DRY up the test classes.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1692 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 47b1aa8 commit ed12b0cac0bda6cda7a7c3c9a5c741fe1bebcc08 @jeremy jeremy committed Jul 5, 2005
Showing with 30 additions and 34 deletions.
  1. +30 −34 actionpack/test/controller/active_record_store_test.rb
@@ -23,25 +23,7 @@
end
-class ActiveRecordStoreTest < Test::Unit::TestCase
- def session_class
- CGI::Session::ActiveRecordStore::Session
- end
-
- def setup
- session_class.create_table!
-
- ENV['REQUEST_METHOD'] = 'GET'
- CGI::Session::ActiveRecordStore.session_class = session_class
-
- @new_session = CGI::Session.new(CGI.new, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
- @new_session['foo'] = 'bar'
- end
-
- def teardown
- session_class.drop_table!
- end
-
+module CommonActiveRecordStoreTests
def test_basics
s = session_class.new(:session_id => '1234', :data => { 'foo' => 'bar' })
assert_equal 'bar', s.data['foo']
@@ -60,14 +42,14 @@ def test_reload_same_session
end
end
+class ActiveRecordStoreTest < Test::Unit::TestCase
+ include CommonActiveRecordStoreTests
-class SqlBypassActiveRecordStoreTest < Test::Unit::TestCase
def session_class
- CGI::Session::ActiveRecordStore::SqlBypass
+ CGI::Session::ActiveRecordStore::Session
end
def setup
- session_class.connection = CGI::Session::ActiveRecordStore::Session.connection
session_class.create_table!
ENV['REQUEST_METHOD'] = 'GET'
@@ -80,22 +62,36 @@ def setup
def teardown
session_class.drop_table!
end
+end
- def test_basics
- s = session_class.new(:session_id => '1234', :data => { 'foo' => 'bar' })
- assert_equal 'bar', s.data['foo']
- assert s.save!
- assert_equal 'bar', s.data['foo']
- assert_not_nil t = session_class.find_by_session_id('1234')
- assert_not_nil t.data
- assert_equal 'bar', t.data['foo']
+class DeprecatedActiveRecordStoreTest < ActiveRecordStoreTest
+ def setup
+ session_class.connection.execute 'create table old_sessions (id integer primary key, sessid text unique, data text)'
+ session_class.table_name = 'old_sessions'
+ session_class.send :setup_sessid_compatibility!
+
+ ENV['REQUEST_METHOD'] = 'GET'
+ CGI::Session::ActiveRecordStore.session_class = session_class
+
+ @new_session = CGI::Session.new(CGI.new, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
+ @new_session['foo'] = 'bar'
end
- def test_reload_same_session
- @new_session.update
- reloaded = CGI::Session.new(CGI.new, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
- assert_equal 'bar', reloaded['foo']
+ def teardown
+ session_class.connection.execute 'drop table old_sessions'
+ session_class.table_name = 'sessions'
+ session_class.send :setup_sessid_compatibility!
+ end
+end
+
+class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
+ def session_class
+ unless @session_class
+ @session_class = CGI::Session::ActiveRecordStore::SqlBypass
+ @session_class.connection = CGI::Session::ActiveRecordStore::Session.connection
+ end
+ @session_class
end
end

0 comments on commit ed12b0c

Please sign in to comment.