Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test cases should see all the cookies, not just cookies that have bee…

…n set in the controller.

Previously this example would always pass, even when cookies.delete was not called.

@request.cookies['foo'] = 'bar'
get :delete_cookie
assert_nil cookies['foo']

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2768 state:committed]
  • Loading branch information...
commit 316f4704eaa8aaba11e7ecebc1da9aa926fdd2d0 1 parent fc46c9b
Craig Smith authored NZKoz committed
View
2  actionpack/lib/action_controller/testing/process.rb
@@ -35,7 +35,7 @@ def flash
end
def cookies
- @response.cookies
+ @request.cookies.merge(@response.cookies)
end
def redirect_to_url
View
17 actionpack/test/controller/test_test.rb
@@ -108,6 +108,11 @@ def create
head :created, :location => 'created resource'
end
+ def delete_cookie
+ cookies.delete("foo")
+ render :nothing => true
+ end
+
private
def rescue_action(e)
raise e
@@ -512,6 +517,18 @@ def test_params_reset_after_post_request
assert @request.params[:foo].blank?
end
+ def test_should_have_knowledge_of_client_side_cookie_state_even_if_they_are_not_set
+ @request.cookies['foo'] = 'bar'
+ get :no_op
+ assert_equal 'bar', cookies['foo']
+ end
+
+ def test_should_detect_if_cookie_is_deleted
+ @request.cookies['foo'] = 'bar'
+ get :delete_cookie
+ assert_nil cookies['foo']
+ end
+
%w(controller response request).each do |variable|
%w(get post put delete head process).each do |method|
define_method("test_#{variable}_missing_for_#{method}_raises_error") do

1 comment on commit 316f470

@brokenladder

I was banging my head into a wall for a whole weekend until I found this. Thank you!

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