Functional testing confusion

I am trying to be a good RORer and write all my tests to achieve 100%
coverage with rcov.

However, I have run up against something that really confuses me.

In my test file

def test_should_mark_task_done
task = tasks(:tasks_001)
post_with_user(‘admin’, :mark_done, {:id => task.id} )
assert_response :success
assert_equal flash[:notice], ‘Task was successfully updated.’
task.reload
assert_equal task.done
end

In my controller:

def mark_done
@task = Task.find(params[:id])
@task.done = true
@task.save
flash[:notice] = ‘Task was successfully updated.’
respond_to do |format|
format.js # mark_done.js.rjs
format.html { redirect_to :action => “index” }
format.xml { head :ok }
end
end

The assert_response :success passes (as it should)
The assert_equal flash[:notice] passes (as it should)
The assert_equal task.done fails (HUH?!?!?!?!)

The code works in practice (ie, it modifies the done column of the
record.)

Any suggestions of where to look?

Thanks,

Alan

Hi –

On Wed, 23 Apr 2008, Alan S. wrote:

post_with_user(‘admin’, :mark_done, {:id => task.id} )
@task = Task.find(params[:id])

The assert_response :success passes (as it should)
The assert_equal flash[:notice] passes (as it should)
The assert_equal task.done fails (HUH?!?!?!?!)

The code works in practice (ie, it modifies the done column of the record.)

Any suggestions of where to look?

You’re not saying what you think it’s equal to. Maybe just:

assert task.done

is what you need?

David


Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.rubypal.com for details and updates!

On 24 Apr 2008, at 14:19, Alan S. wrote:

I apologize, the actual code says
assert task_done

I assume that’s another typo and you mean assert task.done
Have you tried changing the save to a save! (so that you get an
exception saying why it has failed) ?

Fred

I apologize, the actual code says
assert task_done

It was a typo on my part in the email.

–Alan

I just realized that my post is not clear, I still have the problem
that assert task.done fails

You are correct, it should be assert task.done

I know that the save in the actual controller works, because
flash[:notice] gets set appropriately. Just for grins, I changed it
from save, to save! in the controller with no difference.

Thanks for helping me with this!

–Alan

On Thu, Apr 24, 2008 at 9:11 AM, Frederick C.

On 24 Apr 2008, at 15:18, Alan S. wrote:

You are correct, it should be assert task.done

I know that the save in the actual controller works, because
flash[:notice] gets set appropriately. Just for grins, I changed it
from save, to save! in the controller with no difference.

Can you see a matching update query in the test logs ?

Fred

Thank you VERY VERY VERY VERY VERY much. I hadn’t even thought about
looking in the logs. It turns out there was no update query. It
ended up being that my fixtures had bad data in it. I don’t know why
the save! wasn’t complaining the first time, but it is now.

Thanks again,

Alan

On Thu, Apr 24, 2008 at 11:05 AM, Frederick C.