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.
Keith L. (Guest)
on 2006-01-07 03: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
Rick O. (Guest)
on 2006-01-07 04:28
(Received via mailing list)
On 1/6/06, Keith L. <removed_email_address@domain.invalid> 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.
Keith L. (Guest)
on 2006-01-07 04:44
Rick O. wrote:
> On 1/6/06, Keith L. <removed_email_address@domain.invalid> 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.