How to spec a controller method that involves an rjs redirect

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

On Fri, Jan 2, 2009 at 10:01 AM, Nasir J. [email protected] 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.

On Fri, Jan 2, 2009 at 11:01 AM, Nasir J. [email protected] 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. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs