assert_raise(ActiveRecord::RecordNotFound) { User.find(user.id) }
Right from the AWDR book
Bob Silva
http://www.railtie.net/
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Scott NJ
Sent: Wednesday, February 08, 2006 3:00 PM
To: rails@lists.rubyonrails.org
Subject: [Rails] functional test problem
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
login
user = User.find(2)
post :delete_user, {:id => user.id}
assert_equal "User deleted", flash[:notice]
assert_nil User.find(2)
assert_redirected_to :action => ''manage_users''
end
** The Error *******************************
1) Error:
test_delete_user(AdminControllerTest):
ActiveRecord::RecordNotFound: Couldn''t find User with ID=2
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb
:412:in
`find''
test/functional/admin_controller_test.rb:140:in `test_delete_user''
14 tests, 109 assertions, 0 failures, 1 errors
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails