# Rails 2.0 functional tests fail, Testscenario changed?

**URL:** <https://www.ruby-forum.com/t/rails-2-0-functional-tests-fail-testscenario-changed/123515>\
**Category:** Rails\
**Created:** [December 18, 2007, 11:25am UTC](https://www.ruby-forum.com/t/rails-2-0-functional-tests-fail-testscenario-changed/123515 "2007-12-18T11:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4da419/32.png) [@rafael](https://www.ruby-forum.com/u/rafael)\
**Post date:** [December 18, 2007, 11:25am UTC](https://www.ruby-forum.com/t/rails-2-0-functional-tests-fail-testscenario-changed/123515/1 "2007-12-18T11:25:51Z")

</div>

Hi everybody

may be somebody has a hint for that issue, that costs me now hours and  
hours and finally it will be a tiny thing, I guess.  
Anyway thank you very much in advance for helping here.

Our Approach:  
Admin and Backend is seperated through a namespace filestructure  
“admin”. Actually everything works fine,  
except the Functional Tests.  
What should a admin/posts\_controller\_test.rb look like, when I want to  
have an admin/posts\_controller.rb?

My File Structure

app/posts\_controller.rb  
app/admin/posts\_controller.rb

test/posts\_controller\_test.rb  
test/admin/posts\_controller\_test.rb

when I setup my admin test I get always these errors,…

1. Error:  
test\_should\_update\_post(Admin::PostsControllerTest):  
NameError: uninitialized constant PostsController

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/  
active\_support/dependencies.rb:266:in `load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:453:in`const\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/  
active\_support/dependencies.rb:465:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/inflector.rb:257:in`constantize’  
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/  
active\_support/core\_ext/string/inflections.rb:148:in `constantize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/routing.rb:1426:in`recognize’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_controller/assertions/routing\_assertions.rb:138:in  
`recognized_request_for' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/assertions/response_assertions.rb:70:in`assert\_redirected\_to’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_controller/assertions/response\_assertions.rb:62:in `each' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/assertions/response_assertions.rb:62:in`assert\_redirected\_to’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_controller/assertions.rb:54:in `clean_backtrace' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/assertions/response_assertions.rb:54:in`assert\_redirected\_to’  
./test/functional/admin/posts\_controller\_test.rb:45:in  
`test_should_update_post' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/testing/default.rb:7:in`run’

1 tests, 0 assertions, 0 failures, 1 error

my testfile looks like that:

class Admin::PostsControllerTest \< ActionController::TestCase

# Replace this with your real tests.

def test\_should\_update\_posts  
put :update, :id =\> posts(:one).id, :posts =\> { }  
assert\_redirected\_to posts\_path(assigns(:posts))  
end

end

I think it is a namespace issue only,  
but I couldn’t figure it out how and why it (doesn’t)works, so I  
wondered if there changed some things in Rails 2.0?

Any help is really really appreciated

best regards

Rafael

---

<div class="post-metadata">

**Author:** ![rafael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4da419/32.png) [@rafael](https://www.ruby-forum.com/u/rafael)\
**Post date:** [December 18, 2007, 12:31pm UTC](https://www.ruby-forum.com/t/rails-2-0-functional-tests-fail-testscenario-changed/123515/2 "2007-12-18T12:31:10Z")

</div>

On 18 Dec 2007, at 10:25, Rafael wrote:

> end
> 
> I think it is a namespace issue only,  
> but I couldn’t figure it out how and why it (doesn’t)works, so I  
> wondered if there changed some things in Rails 2.0?

Rails tries to figure out the name of the controller (the aim is to  
factor out the pretty much identical setup method in all functional  
tests).  
You can override what it thinks it should test like so

class FooTest \< ActionController::TestCase  
tests MyControllerClass  
end

That said, i’ve just tried it out with namespaced controllers and it  
works without modifications. What’s in admin/post\_controller ?

Fred

---

<div class="post-metadata">

**Author:** ![rafael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4da419/32.png) [@rafael](https://www.ruby-forum.com/u/rafael)\
**Post date:** [December 18, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/rails-2-0-functional-tests-fail-testscenario-changed/123515/3 "2007-12-18T22:39:16Z")

</div>

On 12/18/07, Rafael [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> My File Structure
> 
> app/posts\_controller.rb  
> app/admin/posts\_controller.rb

Is it really this as opposed to:

app/controllers/posts\_controller.rb  
app/controllers/admin/posts\_controller.rb

> test/posts\_controller\_test.rb  
> test/admin/posts\_controller\_test.rb

These also look suspicious, since controller tests normally go under  
test/functional. I’ve become a RSpec guy, so I’m not sure where a  
namespaced controller test is supposed to go in the test hierarchy.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
