Hi all,
I’m trying to do a route test using assert_generates and running into a
bit of trouble.
The controller that I am testing is in a module -
class Admin::AdminPortalController
def index
end
end
I want the user to jump to the AdminPortal/index action when they use
http://myApp/admin, so I’ve put the following in routes.rb
map.admin_portal ‘admin’, :controller => “admin/admin_portal”, :action
=>‘index’
Simple, works fine.
I am putting the test in the generated test file for the controller. The
test is simply
opts = { :controller => 'admin' }
assert_generates "admin/admin_portal/index", opts
It fails - apparently the generated path is just “/admin”. Any hints
here?
TIA
Keith
On 1/6/06, Keith L. [email protected] wrote:
opts = { :controller => 'admin' }
assert_generates "admin/admin_portal/index", opts
It fails - apparently the generated path is just “/admin”. Any hints
here?
I think you’re slightly misunderstanding the way routes work. In your
example:
map.admin_portal ‘admin’, :controller => “admin/admin_portal”, :action
=>‘index’
/admin is not redirecting to that controller… Going to /admin will
yield those options and process that controller action.
assert_routing ‘admin’, :controller => “admin/admin_portal”, :action
=>‘index’
This asserts that ‘admin’ is recognized by those options, AND that
those options generate the url /admin.
Rick O. wrote:
On 1/6/06, Keith L. [email protected] wrote:
opts = { :controller => 'admin' }
assert_generates "admin/admin_portal/index", opts
It fails - apparently the generated path is just “/admin”. Any hints
here?
I think you’re slightly misunderstanding the way routes work. In your
example:
map.admin_portal ‘admin’, :controller => “admin/admin_portal”, :action
=>‘index’
/admin is not redirecting to that controller… Going to /admin will
yield those options and process that controller action.
assert_routing ‘admin’, :controller => “admin/admin_portal”, :action
=>‘index’
This asserts that ‘admin’ is recognized by those options, AND that
those options generate the url /admin.
You are right - I’m not too clear on routing - just getting my feet wet
in this part of Rails. Your solution worked, so thanks!
Keith