SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using url_for() in a functional test

    Hallo -- I have an assertion in a functional test that looks like this:
    Code:
    assert_redirected_to :controller=>'properties',:action=>'list'
    This creates this error:
    Code:
    response is not a redirection to all of the options supplied (redirection is <"http://test.host/properties/list">)
    This is due, I believe (tell me if I'm wrong!), to the fact that the code that generates the url uses:
    Code:
    url=url_for(:controller=>'properties',:action=>'list')
    # more code here...
    redirect_to(url)
    However, when I try to rewrite my assertion to use the url_for() function like so:
    Code:
    assert_redirected_to(url_for(:controller=>'properties',:action=>'list'))
    I get a NoMethodError for url_for().
    Can anyone help here?
    Cheers,
    doug.

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perhaps

    Code:
    assert_redirected_to(ActionController::Base::url_for(:controller=>'properties',:action=>'list'))
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming that before your assert_redirected_to() call you called

    redirect_tocontroller=>'properties', :action=>list)

    If this is the case, I think you only need to call assert_redirected_toaction=>'list') as rails knows you're using the 'properties' controller.

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a reason why you are doing:

    Code:
    url=url_for(:controller=>'properties',:action=>'list')
    # more code here...
    redirect_to(url)
    When you can just do:

    Code:
    redirect_to :controller=>'properties',:action=>'list'
    Its worth pointing out that its Ruby convention not to use parentheses around your method parameters in most circumstances.

    http://www.rubygarden.org/ruby?RubyStyleGuide

  5. #5
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for those -- the reason for any stupid errors is that I am still learning ruby & rails. Well, that & my being stupid anyway...
    Thanks alot,
    doug.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •