Skip to content

Commit

Permalink
r3306@asus: jeremy | 2005-11-23 17:39:24 -0800
Browse files Browse the repository at this point in the history
 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
jeremy committed Nov 24, 2005
1 parent 3fcec37 commit 2b4dd8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Expand Up @@ -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]
Expand Down
23 changes: 9 additions & 14 deletions actionpack/lib/action_controller/session/active_record_store.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/asset_tag_helper.rb
Expand Up @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions actionpack/test/controller/active_record_store_test.rb
Expand Up @@ -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.'
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b4dd8c

Please sign in to comment.