views:

281

answers:

1

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.

+3  A: 

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.

insane.dreamer
that does exactly what I want. thanks!
dbrown0708
Thanks! This helped me out a lot too! :)
CalebHC