# Testing Cookies in Rails

**URL:** <https://www.ruby-forum.com/t/testing-cookies-in-rails/129376>\
**Category:** Rails\
**Created:** [February 17, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/testing-cookies-in-rails/129376 "2008-02-17T22:19:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruby\_newbie1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@ruby\_newbie1](https://www.ruby-forum.com/u/ruby_newbie1)\
**Post date:** [February 17, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/testing-cookies-in-rails/129376/1 "2008-02-17T22:19:26Z")

</div>

Hello,

I created a controller and within the controller I have two separate  
functions that involve the cookie that I implemented:

def login  
cookies[:login] = 1  
end

def logout  
if cookies[:login]  
cookies.delete :login  
end  
end

When I try this out on the actual site, it seems to work rather well.  
However, I also must create a functional test that tests for these  
conditions in an automated manner. I managed to find a plugin called  
assert\_cookie that allows me to assert if there is a cookie at the  
current time or not. When I attempted to use it, it did not have the  
desired results.

The test came out to be like this:

post :login  
assert\_cookie :login

post :logout  
assert\_no\_cookie :login

The result was that the first assertion succeeded but the second one  
failed.

Using Netbeans debugger, I was able to step through the test to see  
what was going on. It seems that when it enters the logout method,  
the cookie does not seem to exist. It will check for cookies[:login]  
and skip over the delete step. I tried to sift through @response and  
other local variables, but cannot seem to figure why this is so. Does  
anybody know what’s going on? Thanks in advance.
