aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/session/active_record_store.rb13
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb2
-rw-r--r--actionpack/test/controller/active_record_store_test.rb12
4 files changed, 16 insertions, 13 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 5f44322290..931b4c4e6d 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* 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]
* Use Element.update('id', 'html') instead of $('id').innerHTML = 'html' in JavaScriptGenerator#replace_html so that script tags are evaluated. [Sam Stephenson]
diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb
index 4a6b05c917..c247bd4785 100644
--- a/actionpack/lib/action_controller/session/active_record_store.rb
+++ b/actionpack/lib/action_controller/session/active_record_store.rb
@@ -117,17 +117,11 @@ class CGI
end
end
+ attr_writer :data
+
# 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
@@ -284,6 +278,7 @@ class CGI
raise CGI::Session::NoSession, 'uninitialized session'
end
@session = @@session_class.new(:session_id => session_id, :data => {})
+ @session.save
end
end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 68bdfd80a0..c98b7a3638 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -35,7 +35,7 @@ module ActionView
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:
diff --git a/actionpack/test/controller/active_record_store_test.rb b/actionpack/test/controller/active_record_store_test.rb
index 5c612865c3..2038a80119 100644
--- a/actionpack/test/controller/active_record_store_test.rb
+++ b/actionpack/test/controller/active_record_store_test.rb
@@ -15,12 +15,12 @@ require 'action_controller/session/active_record_store'
#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 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
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)