Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did post fail in my Rails functional test?

When I run a post in my Rails functional test

setup do
  post :create, :user => Factory.attributes_for(:user)
end

and it fails, I don't get any feedback as to why. I know that it fails because my assertion to make sure that there's one additional record in the database fails.

I tried to do

setup do
  post :create, :user => Factory.attributes_for(:user)
  assert_valid @controller.object
end

but object is a protected method.

How can I examine the errors on the model object that results from the post call?

I'm using Shoulda and Factory Girl, but I suspect that doesn't matter.

like image 798
dbrown0708 Avatar asked Apr 08 '09 01:04

dbrown0708


1 Answers

Add the following assertion:

assert_nil assigns(:user).errors

Which will fail if there were errors saving your object (perhaps a validation), and show you the value of the errors object.

like image 63
insane.dreamer Avatar answered Oct 30 '22 11:10

insane.dreamer