Forum: Ruby on Rails functional test problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eecd295cdec2454c66e2015036a39408?d=identicon&s=25 Scott Nj (scottnj)
on 2006-02-09 00:00
I am trying to write a test for my delete method.

I find a User in the db by its id, do the delete action, then I want to
see if it is still in the db.

How do I check that the User IS Deleted without causing errors?

** My Test ********************************
  def test_delete_user
    user = User.find(2)
    post :delete_user, {:id =>}
    assert_equal "User deleted", flash[:notice]
    assert_nil    User.find(2)
    assert_redirected_to :action => 'manage_users'
** The Error *******************************
  1) Error:
ActiveRecord::RecordNotFound: Couldn't find User with ID=2
    test/functional/admin_controller_test.rb:140:in `test_delete_user'

14 tests, 109 assertions, 0 failures, 1 errors
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-02-09 00:40
(Received via mailing list)
assert_raise(ActiveRecord::RecordNotFound) { User.find( }

Right from the AWDR book

Bob Silva
This topic is locked and can not be replied to.