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
--
Posted via http://www.ruby-forum.com/.
On 1/6/06, Keith Lancaster <klancaster1957@gmail.com> wrote:> 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?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 Olson wrote:> On 1/6/06, Keith Lancaster <klancaster1957@gmail.com> 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 -- Posted via http://www.ruby-forum.com/.