Forum: Ruby on Rails problem with cookies in tests (TDD)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
84c87f57a9bfcdc9e14ae00d909e3de4?d=identicon&s=25 Benjamin Kuz (Guest)
on 2006-01-10 23:12
The problem I'm having is that I can't seem to destroy the cookies and
assert that they were indeed destroyed inside the test.
The code to do this does work - the cookies are created, and are
destroyed when this is done in a browser, but I can't seem to make the
test pass.

account_signup_test.rb

  def test_should_pass_if_logout_destroys_cookie_data
    post :login, { :user => { :login => 'ben', :password => 'password'
}, :remember => 1 }
    assert_equal(User.hash_password('password'), cookies["password"][0])
    assert_equal('ben', cookies["login"][0])
    get :logout
    assert_nil cookies["password"][0]
    assert_nil cookies["login"][0]
  end

account_controller.rb

  def logout
    session['user'] = nil
    cookies.delete :login if cookies[:login]
    cookies.delete :password if cookies[:password]
  end

rake test failure (assert_nil cookies["password"][0] is what fails):

  1) Failure:
test_should_pass_if_logout_destroys_cookie_data(AccountSignupTest)
[./test/functional/account/account_signup_test.rb:169]:
<nil> expected but was
<"5f4dcc3b5aa765d61d8327deb882cf99">.

---

Thanks in advance,

Benjamin Kuz
Bravenet Web Services
This topic is locked and can not be replied to.