Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge [5512] from trunk.
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5513 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 13, 2006
1 parent b8a5d39 commit 35240ba
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Always clear model associations from session. #4795 [sd@notso.net, andylien@gmail.com]

* Update to Prototype 1.5.0_rc2. [Sam Stephenson]

* Remove JavaScriptLiteral in favor of ActiveSupport::JSON::Variable. [Sam Stephenson]
Expand Down
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/session/drb_store.rb
Expand Up @@ -26,6 +26,10 @@ def close
def delete
@@session_data.delete(@session_id)
end

def data
@@session_data[@session_id]
end
end
end
end
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/session/mem_cache_store.rb
Expand Up @@ -93,6 +93,10 @@ def delete
end
@session_data = {}
end

def data
@session_data
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_controller/session_management.rb
Expand Up @@ -120,16 +120,16 @@ def set_session_options(request)
end

def process_cleanup_with_session_management_support
process_cleanup_without_session_management_support
clear_persistent_model_associations
process_cleanup_without_session_management_support
end

# Clear cached associations in session data so they don't overflow
# the database field. Only applies to ActiveRecordStore since there
# is not a standard way to iterate over session data.
def clear_persistent_model_associations #:doc:
if defined?(@_session) && @_session.instance_variables.include?('@data')
session_data = @_session.instance_variable_get('@data')
if defined?(@_session) && @_session.respond_to?(:data)
session_data = @_session.data

if session_data && session_data.respond_to?(:each_value)
session_data.each_value do |obj|
Expand Down
33 changes: 23 additions & 10 deletions actionpack/lib/action_controller/test_process.rb
Expand Up @@ -38,7 +38,7 @@ def initialize(query_parameters = nil, request_parameters = nil, session = nil)

def reset_session
@session = TestSession.new
end
end

def raw_post
if raw_post = env['RAW_POST_DATA']
Expand Down Expand Up @@ -275,27 +275,40 @@ class TestResponse < AbstractResponse #:nodoc:
end

class TestSession #:nodoc:
def initialize(attributes = {})
attr_accessor :session_id

def initialize(attributes = nil)
@session_id = ''
@attributes = attributes
@saved_attributes = nil
end

def data
@attributes ||= @saved_attributes || {}
end

def [](key)
@attributes[key]
data[key]
end

def []=(key, value)
@attributes[key] = value
data[key] = value
end

def session_id
""
def update
@saved_attributes = @attributes
end

def update() end
def close() end
def delete() @attributes = {} end
def delete
@attributes = nil
end

def close
update
delete
end
end

# Essentially generates a modified Tempfile object similar to the object
# you'd get from the standard library CGI module in a multipart
# request. This means you can use an ActionController::TestUploadedFile
Expand Down
51 changes: 51 additions & 0 deletions actionpack/test/controller/session_management_test.rb
Expand Up @@ -44,6 +44,49 @@ def another
end
end

class AssociationCachingTestController < ActionController::Base
class ObjectWithAssociationCache
def initialize
@cached_associations = false
end

def fetch_associations
@cached_associations = true
end

def clear_association_cache
@cached_associations = false
end

def has_cached_associations?
@cached_associations
end
end

def show
session[:object] = ObjectWithAssociationCache.new
session[:object].fetch_associations
if session[:object].has_cached_associations?
render :text => "has cached associations"
else
render :text => "does not have cached associations"
end
end

def tell
if session[:object]
if session[:object].has_cached_associations?
render :text => "has cached associations"
else
render :text => "does not have cached associations"
end
else
render :text => "there is no object"
end
end
end


def setup
@request, @response = ActionController::TestRequest.new,
ActionController::TestResponse.new
Expand Down Expand Up @@ -91,4 +134,12 @@ def test_session_store_setting
assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store
end
end

def test_process_cleanup_with_session_management_support
@controller = AssociationCachingTestController.new
get :show
assert_equal "has cached associations", @response.body
get :tell
assert_equal "does not have cached associations", @response.body
end
end

0 comments on commit 35240ba

Please sign in to comment.