How to spec a controller method that involves an rjs redirect


#1

Hi everyone,

What is the best way to spec a controller method that involves an rjs
redirect? Something like this

def index
 url_to = @parent ? auction_bids_path(@parent) : auctions_path
 render :update do |page|
   page.redirect_to(url_to)
 end
end

I tried
 response.should have_rjs
for the redirect but it didnt work. Any help would be appreciated.

Thanks


#2

On Fri, Jan 2, 2009 at 10:01 AM, Nasir J. removed_email_address@domain.invalid wrote:

end

I tried
response.should have_rjs
for the redirect but it didnt work. Any help would be appreciated.

Please be more specific when you say “it didn’t work.” What precisely
was the code in the spec and what precisely was the error you got.


#3

On Fri, Jan 2, 2009 at 11:01 AM, Nasir J. removed_email_address@domain.invalid wrote:

What is the best way to spec a controller method that involves an rjs
redirect? Something like this

Consider:

response.should =~ /window.location.href = ‘(whatever your expected
path is)’;/

I didn’t confirm that regex, obviously. But the concept is pretty
simple: if you know how the RJS redirect works and what Javascript is
supposed to be generated, then test for its presence in the response.
If it’s there, your controller logic worked.


Have Fun,
Steve E. (removed_email_address@domain.invalid)
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org