Forum: RSpec How to spec a controller method that involves an rjs redirect

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.
Nasir J. (Guest)
on 2009-01-02 18:03
(Received via mailing list)
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
David C. (Guest)
on 2009-01-03 22:33
(Received via mailing list)
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.
Stephen E. (Guest)
on 2009-01-04 06:18
(Received via mailing list)
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
This topic is locked and can not be replied to.