From 8350925bec434168f56b4fae22b5298cb4a83c41 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 1 Dec 2015 14:37:20 -0500 Subject: [PATCH] Stop violating law of demeter in response cookie_jar This adds a new method to request and response so we don't need to violate the law of demeter. We are changing `Request` and `Response` so that they always have a `cookie_jar` This is a continuation on work to combine integration and controller test code bases in Rails. --- actionpack/lib/action_dispatch/http/request.rb | 3 +++ actionpack/lib/action_dispatch/http/response.rb | 2 +- actionpack/lib/action_dispatch/middleware/cookies.rb | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 482917d71b..29cf821090 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -63,6 +63,9 @@ def initialize(env) @ip = nil end + def commit_cookie_jar! # :nodoc: + end + def check_path_parameters! # If any of the path parameters has an invalid encoding then # raise since it's likely to trigger errors further on. diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index a4852d7031..9a10dc73d9 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -413,7 +413,7 @@ def before_committed def before_sending headers.freeze - request.cookie_jar.commit! + request.commit_cookie_jar! end def build_buffer(response, body) diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 65baf117ba..3477aa8b29 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -12,6 +12,12 @@ def cookie_jar end # :stopdoc: + prepend Module.new { + def commit_cookie_jar! + cookie_jar.commit! + end + } + def have_cookie_jar? has_header? 'action_dispatch.cookies'.freeze end -- GitLab