Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7535 (closed defect: duplicate)

Opened 4 years ago

Last modified 3 years ago

assert_redirected_to crashes testing if redirect_to uses symbols

Reported by: jordi Assigned to: core
Priority: normal Milestone:
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc: shoe

Description

While following Agile2's example code, I had a test method such that:

def test_index

get :index assert_redirected_to :action => 'login' assert flash[:notice] == 'Please log in'

end

And in the controller, I had:

def authorize

unless User.find_by_id(session[:user_id])

session[:original_uri] = request.request_uri flash[:notice] = 'Please log in' redirect_to :controller => :login, :action => :login

end

end

I'm not entirely sure this should work, but redirect_to seems to work the same with 'login' or :login. It's just the test that crashes in the symbol case.

What I get is:

NoMethodError: undefined method first' for :login:Symbol (...) action_controller/assertions/response_assertions.rb:72:in assert_redirected_to'

Change History

02/12/07 05:33:06 changed by jordi

Ok, here's the code, better formatted:

# Code in the controller functional test
def test_index
  get :index
  assert_redirected_to :action => 'login'
  assert flash[:notice] == 'Please log in'
end

# Code in ApplicationController
def authorize
  unless User.find_by_id(session[:user_id])
    session[:original_uri] = request.request_uri
    flash[:notice]         = 'Please log in'
    redirect_to :controller => :login, :action => :login
  end
end

02/12/07 06:56:33 changed by jordi

  • version changed from 1.2.1 to edge.
  • milestone deleted.

Just tested this against edge. Same thing happens there. Changing "version" in ticket.

03/25/07 14:55:10 changed by rhymes

I dug a bit in the code and the problems seems to be here <http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/assertions/response_assertions.rb#L72>

It expects an array but with "assert_redirected_to :action => :login" it gets a mere symbol there. The same using login as a string or without the :action (eg. assert_redirected_to :login)

06/17/07 20:15:56 changed by wycats

I was able to write a fix for this bug, but when I tried to write a test case, Rails threw an error on redirect_to :controller => :symbol. Can someone confirm that redirect_to :controller => :symbol is actually valid?

(follow-up: ↓ 6 ) 09/10/07 21:57:01 changed by shoe

  • cc set to shoe.

Somehow I missed this ticket when I filed ticket #9535 ( http://dev.rubyonrails.org/ticket/9535 ).

But anyway, I've attached a fix for this there, and it includes unit tests which do pass.

(in reply to: ↑ 5 ) 09/11/07 12:57:30 changed by boone

Replying to shoe:

Somehow I missed this ticket when I filed ticket #9535 ( http://dev.rubyonrails.org/ticket/9535 ).

I think you meant #9525.

Thanks for working on it.

09/11/07 13:44:21 changed by norbert

  • status changed from new to closed.
  • resolution set to duplicate.

As the forementioned #9525 already has a patch, I think this ticket can be closed. Please continue the discussion in the other ticket.