I hate cookies. Or maybe I’m just feeling schizo today. Actually, I do love cookies, just not testing them with Rails.
I’ve added assert_no_cookie method to the assert_cookie plugin. That’s because in your functional tests, cookies['chocolate'] may be something, nil, or an empty array depending on what you’ve just done. For example, in this code I had tried assert_nil cookies['pass'] but that failed because cookies['pass'] was [] after calling cookies.delete :pass in the controller:
def test_destroy_should_remove_persistent_login_cookie
post :create, :username => 'brian.ford', :password => 'secret',
:remember_me => '1'
pass = cookies['pass']
@request.cookies['pass'] = cookies['pass']
post :destroy, :_method => 'delete'
assert_no_cookie :pass
user = User.find_by_username 'brian.ford'
assert_nil user.persistent_logins.find_by_pass(pass)
end
Anyway, as before, you can get this by script/plugin http://svn.planetargon.org/rails/plugins/assert_cookie.
And thanks yet again to Pluit Solutions for helping me keep my head straight about how to work with cookies in functional tests. Next stop, a patch for Rails (would a generous soul please donate some time to this so I don’t have to).