aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/assertions/action_pack_assertions.rb13
-rw-r--r--actionpack/test/controller/cookie_test.rb12
3 files changed, 24 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 33e5fa417b..d0cc7b35bf 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added assert_no_cookie and fixed assert_cookie_equal to deal with non-existing cookies #979 [bitsweat]
+
* Fixed :overwrite_param so it doesn't delete but reject elements from @request.parameters #982 [raphinou@yahoo.com]
* Added :method option to verify for ensuring that either GET, POST, etc is allowed #984 [Jamis Buck]
diff --git a/actionpack/lib/action_controller/assertions/action_pack_assertions.rb b/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
index d1d5cafc08..9bbcc5b83f 100644
--- a/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
@@ -63,10 +63,19 @@ module Test #:nodoc:
# -- cookie assertions ---------------------------------------------------
+ def assert_no_cookie(key = nil, message = nil)
+ response = acquire_assertion_target
+ actual = response.cookies[key]
+ msg = build_message(message, "<?> not expected in cookies['?']", actual, key)
+ assert_block(msg) { actual.nil? or actual.empty? }
+ end
+
def assert_cookie_equal(expected = nil, key = nil, message = nil)
response = acquire_assertion_target
- msg = build_message(message, "<?> expected in cookies['?'] but was <?>", expected, key, response.cookies[key.to_s].first)
- assert_block(msg) { expected == response.cookies[key.to_s].first }
+ actual = response.cookies[key]
+ actual = actual.first if actual
+ msg = build_message(message, "<?> expected in cookies['?'] but was <?>", expected, key, actual)
+ assert_block(msg) { expected == actual }
end
# -- flash assertions ---------------------------------------------------
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 2b5b1cae9f..f0189ebb11 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -28,6 +28,11 @@ class CookieTest < Test::Unit::TestCase
render_text "hello world"
end
+ def access_frozen_cookies
+ @cookies["will"] = "work"
+ render_text "hello world"
+ end
+
def rescue_action(e) raise end
end
@@ -63,8 +68,13 @@ class CookieTest < Test::Unit::TestCase
assert_equal 2, process_request.headers["cookie"].size
end
+ def test_setting_test_cookie
+ @request.action = "access_frozen_cookies"
+ assert_nothing_raised { process_request }
+ end
+
private
def process_request
TestController.process(@request, @response)
end
-end \ No newline at end of file
+end