aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-21 16:01:41 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-21 16:36:28 -0700
commitbdbe390a98acbebcfd48dca28c79d3296c8d3981 (patch)
tree18fbee91e915449ebcb026e506ca26b81c4bca6d /activerecord
parent1f8edb996b97da0df6ed0f0e0ceffef9d84119ce (diff)
downloadrails-bdbe390a98acbebcfd48dca28c79d3296c8d3981.tar.gz
rails-bdbe390a98acbebcfd48dca28c79d3296c8d3981.tar.bz2
rails-bdbe390a98acbebcfd48dca28c79d3296c8d3981.zip
initializing instance variables
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/session_store.rb7
-rw-r--r--activerecord/test/cases/session_store/session_test.rb63
2 files changed, 69 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb
index 0c2db4156b..feb9e2e8f6 100644
--- a/activerecord/lib/active_record/session_store.rb
+++ b/activerecord/lib/active_record/session_store.rb
@@ -119,6 +119,11 @@ module ActiveRecord
end
end
+ def initialize(attributes = nil)
+ @data = nil
+ super
+ end
+
# Lazy-unmarshal session state.
def data
@data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {}
@@ -128,7 +133,7 @@ module ActiveRecord
# Has the session been loaded yet?
def loaded?
- !!@data
+ @data
end
private
diff --git a/activerecord/test/cases/session_store/session_test.rb b/activerecord/test/cases/session_store/session_test.rb
new file mode 100644
index 0000000000..bb2e1ec97a
--- /dev/null
+++ b/activerecord/test/cases/session_store/session_test.rb
@@ -0,0 +1,63 @@
+require 'cases/helper'
+require 'action_dispatch'
+require 'active_record/session_store'
+
+module ActiveRecord
+ class SessionStore
+ class SessionTest < ActiveRecord::TestCase
+ def setup
+ super
+ Session.drop_table! if Session.table_exists?
+ end
+
+ def test_data_column_name
+ # default column name is 'data'
+ assert_equal 'data', Session.data_column_name
+ end
+
+ def test_table_name
+ assert_equal 'sessions', Session.table_name
+ end
+
+ def test_create_table!
+ assert !Session.table_exists?
+ Session.create_table!
+ assert Session.table_exists?
+ Session.drop_table!
+ assert !Session.table_exists?
+ end
+
+ def test_find_by_sess_id_compat
+ klass = Class.new(Session) do
+ def self.session_id_column
+ 'sessid'
+ end
+ end
+ klass.create_table!
+
+ assert klass.columns_hash['sessid'], 'sessid column exists'
+ session = klass.new(:data => 'hello')
+ session.sessid = 100
+ session.save!
+
+ found = klass.find_by_session_id(100)
+ assert_equal session, found
+ assert_equal session.sessid, found.session_id.to_i
+ ensure
+ klass.drop_table!
+ end
+
+ def test_find_by_session_id
+ Session.create_table!
+ s = Session.create!(:data => 'world', :session_id => 10)
+ assert_equal s, Session.find_by_session_id(10)
+ Session.drop_table!
+ end
+
+ def test_loaded?
+ s = Session.new
+ assert !s.loaded?, 'session is not loaded'
+ end
+ end
+ end
+end