Skip to content
Browse files

Merge pull request #7316 from brainopia/backport_fix_session_store_op…

…tions

Backport of "Support cookie jar options for all cookie stores" for 3.2-stable
  • Loading branch information...
2 parents dad717a + 2e04a34 commit 20f18cbc148270112c670189cf5489900a2271dc @rafaelfranca rafaelfranca committed Aug 11, 2012
View
5 actionpack/CHANGELOG.md
@@ -2,6 +2,11 @@
* `javascript_include_tag :all` will now not include `application.js` if the file does not exists. *Prem Sichanugrist*
+* Support cookie jar options (e.g., domain :all) for all session stores.
+ Fixes GH#3047, GH#2483.
+
+ *Ravil Bayramgalin*
+
## Rails 3.2.8 (Aug 9, 2012) ##
View
10 actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -170,12 +170,14 @@ def []=(key, options)
options = { :value => value }
end
- @cookies[key.to_s] = value
-
handle_options(options)
- @set_cookies[key.to_s] = options
- @delete_cookies.delete(key.to_s)
+ if @cookies[key.to_s] != value or options[:expires]
+ @cookies[key.to_s] = value
+ @set_cookies[key.to_s] = options
+ @delete_cookies.delete(key.to_s)
+ end
+
value
end
View
7 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -74,6 +74,13 @@ def stale_session_check!
class AbstractStore < Rack::Session::Abstract::ID
include Compatibility
include StaleSessionCheck
+
+ private
+
+ def set_cookie(env, session_id, cookie)
+ request = ActionDispatch::Request.new(env)
+ request.cookie_jar[key] = cookie
+ end
end
end
end
View
7 actionpack/test/activerecord/active_record_store_test.rb
@@ -256,6 +256,13 @@ def test_incoming_invalid_session_id_via_parameter_should_be_ignored
end
end
+ def test_session_store_with_all_domains
+ with_test_route_set(:domain => :all) do
+ get '/set_session_value'
+ assert_response :success
+ end
+ end
+
private
def with_test_route_set(options = {})
View
14 actionpack/test/dispatch/cookies_test.rb
@@ -179,6 +179,18 @@ def test_setting_cookie
assert_equal({"user_name" => "david"}, @response.cookies)
end
+ def test_setting_the_same_value_to_cookie
+ request.cookies[:user_name] = 'david'
+ get :authenticate
+ assert response.cookies.empty?
+ end
+
+ def test_setting_the_same_value_to_permanent_cookie
+ request.cookies[:user_name] = 'Jamie'
+ get :set_permanent_cookie
+ assert_equal response.cookies, 'user_name' => 'Jamie'
+ end
+
def test_setting_with_escapable_characters
get :set_with_with_escapable_characters
assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"
@@ -564,4 +576,4 @@ def assert_not_cookie_header(expected)
assert_not_equal expected.split("\n"), header
end
end
-end
+end

0 comments on commit 20f18cb

Please sign in to comment.
Something went wrong with that request. Please try again.