# Functional tests and active scaffold: unexpected assertion f

**URL:** <https://www.ruby-forum.com/t/functional-tests-and-active-scaffold-unexpected-assertion-f/107693>\
**Category:** Rails\
**Created:** [June 25, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/functional-tests-and-active-scaffold-unexpected-assertion-f/107693 "2007-06-25T13:44:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gian](https://www.ruby-forum.com/u/gian)\
**Post date:** [June 25, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/functional-tests-and-active-scaffold-unexpected-assertion-f/107693/1 "2007-06-25T13:44:36Z")

</div>

Hello,

I’m writing a functional test for a controller that uses active  
scaffold.

def test\_presence\_of\_field  
login\_as(:peter)  
profile = Profile.find :first  
get :edit, {:id =\> profile.id}  
assert\_response 200  
assert\_select “textarea#record\_free\_text\_ec”  
end

I was expecting the first ‘assert 200’ to give me a green bar,  
but added it for confirmation, and indeed it gives me te  
following failure:  
Expected response to be a \<200\>, but was \<0\>

The same assertion works fine when I don’t use  
active scaffold.

Does anyone know how to solve this problem?

Cheers,

Gian

---

<div class="post-metadata">

**Author:** ![gian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gian](https://www.ruby-forum.com/u/gian)\
**Post date:** [June 26, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/functional-tests-and-active-scaffold-unexpected-assertion-f/107693/2 "2007-06-26T13:07:16Z")

</div>

Just for the records, for whoever might end up on this thread.

I found out what the problem was, it has nothing to do with active  
scaffold.

The cause of this problem was a missing fixture in my tests.

More specifically. I use the plug in act\_as\_authenticated, and  
the first line in my tests is usually login\_as(:peter), that  
sets the user as logged in.

The method login\_as worked fine, and the @current\_user instance  
variable was set in my controllers, but the instances of an  
association  
(i.e. has\_and\_belongs\_to\_many :roles) where not made and not set  
in the specific user instance, this caused some conditions to fail and  
resulted in a redirect.

Moral of the story: I needed to add an extra fixture to my functional  
test.
