Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

r3306@asus: jeremy | 2005-11-23 17:39:24 -0800

 Apply [3100], [3108] to stable.  Makes new ActiveRecordStore sessions work correctly with components.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3179 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 2b4dd8c6e7b772514d2f516b8c532fdcfac180f9 1 parent 3fcec37
@jeremy jeremy authored
View
2  actionpack/CHANGELOG
@@ -8,6 +8,8 @@
* Correct docs for automatic layout assignment. #2610. [Charles M. Gerungan]
+* Always create new AR sessions rather than trying too hard to avoid database traffic. #2731 [Jeremy Kemper]
+
* Update to Prototype 1.4.0_rc4. Closes #2943 (old Array.prototype.reverse behavior can be obtained by passing false as an argument). [Sam Stephenson]
* Update to Prototype 1.4.0_rc3. Closes #1893, #2505, #2550, #2748, #2783. [Sam Stephenson]
View
23 actionpack/lib/action_controller/session/active_record_store.rb
@@ -80,8 +80,8 @@ def find_by_session_id(session_id)
find_by_session_id(session_id)
end
- def marshal(data) Base64.encode64(Marshal.dump(data)) end
- def unmarshal(data) Marshal.load(Base64.decode64(data)) end
+ def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
+ def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
def create_table!
connection.execute <<-end_sql
@@ -119,18 +119,12 @@ def self.find_by_session_id(session_id)
# Lazy-unmarshal session state.
def data
- unless @data
- case d = read_attribute(@@data_column_name)
- when String
- @data = self.class.unmarshal(d)
- else
- @data = d || {}
- end
- end
- @data
+ @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {}
end
private
+ attr_writer :data
+
def marshal_data!
write_attribute(@@data_column_name, self.class.marshal(self.data))
end
@@ -193,8 +187,8 @@ def find_by_session_id(session_id)
end
end
- def marshal(data) Base64.encode64(Marshal.dump(data)) end
- def unmarshal(data) Marshal.load(Base64.decode64(data)) end
+ def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
+ def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
def create_table!
@@connection.execute <<-end_sql
@@ -230,7 +224,7 @@ def new_record?
def data
unless @data
if @marshaled_data
- @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil
+ @data, @marshaled_data = self.class.unmarshal(@marshaled_data) || {}, nil
else
@data = {}
end
@@ -284,6 +278,7 @@ def initialize(session, option = nil)
raise CGI::Session::NoSession, 'uninitialized session'
end
@session = @@session_class.new(:session_id => session_id, :data => {})
+ @session.save
end
end
View
2  actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -35,7 +35,7 @@ def javascript_path(source)
compute_public_path(source, 'javascripts', 'js')
end
- JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls']
+ JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls'] unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
@@javascript_default_sources = JAVASCRIPT_DEFAULT_SOURCES.dup
# Returns a script include tag per source given as argument. Examples:
View
12 actionpack/test/controller/active_record_store_test.rb
@@ -15,12 +15,12 @@
#ActiveRecord::Base.logger = Logger.new($stdout)
begin
- CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:')
+ CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
CGI::Session::ActiveRecordStore::Session.connection
rescue Object
$stderr.puts 'SQLite 3 unavailable; falling back to SQLite 2.'
begin
- CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite', :dbfile => ':memory:')
+ CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite', :database => ':memory:')
CGI::Session::ActiveRecordStore::Session.connection
rescue Object
$stderr.puts 'SQLite 2 unavailable; skipping ActiveRecordStore test suite.'
@@ -68,10 +68,16 @@ def setup
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)
+ @cgi = CGI.new
+ @new_session = CGI::Session.new(@cgi, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
@new_session['foo'] = 'bar'
end
+ def test_another_instance
+ @another = CGI::Session.new(@cgi, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
+ assert_equal @new_session.session_id, @another.session_id
+ end
+
def test_model_attribute
assert_kind_of CGI::Session::ActiveRecordStore::Session, @new_session.model
assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
Please sign in to comment.
Something went wrong with that request. Please try again.