Forum: Ruby on Rails Functional tests with routes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-01-07 02:50
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
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-01-07 03:28
(Received via mailing list)
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.
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-01-07 03:44
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
This topic is locked and can not be replied to.