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.
170b5dc385cc9ddf78ed01bcf1e6990a?d=identicon&s=25 Nasir Jamal (Guest)
on 2009-01-02 17: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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-01-03 21:33
(Received via mailing list)
On Fri, Jan 2, 2009 at 10:01 AM, Nasir Jamal <nas35_in@yahoo.com> 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.
994e42bda994be2cd1d791f18ee6d561?d=identicon&s=25 Stephen Eley (Guest)
on 2009-01-04 05:18
(Received via mailing list)
On Fri, Jan 2, 2009 at 11:01 AM, Nasir Jamal <nas35_in@yahoo.com> 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 Eley (sfeley@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
This topic is locked and can not be replied to.