# Functional testing confusion

**URL:** <https://www.ruby-forum.com/t/functional-testing-confusion/135671>\
**Category:** Rails\
**Created:** [April 24, 2008, 2:55am UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671 "2008-04-24T02:55:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 2:55am UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/1 "2008-04-24T02:55:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 4:01am UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/2 "2008-04-24T04:01:48Z")

</div>

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](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/3 "2008-04-24T16:12:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/4 "2008-04-24T15:48:46Z")

</div>

I apologize, the actual code says  
assert task\_done

It was a typo on my part in the email.

–Alan

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/5 "2008-04-24T17:53:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/6 "2008-04-24T16:18:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/7 "2008-04-24T18:06:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apswartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@apswartz](https://www.ruby-forum.com/u/apswartz)\
**Post date:** [April 24, 2008, 8:15pm UTC](https://www.ruby-forum.com/t/functional-testing-confusion/135671/8 "2008-04-24T20:15:01Z")

</div>

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.
