Nasir Jamal
2009-Jan-02 16:01 UTC
[rspec-users] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090102/4314cdc2/attachment.html>
David Chelimsky
2009-Jan-03 20:31 UTC
[rspec-users] How to spec a controller method that involves an rjs redirect
On Fri, Jan 2, 2009 at 10:01 AM, Nasir Jamal <nas35_in at yahoo.com> wrote:> 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.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 Eley
2009-Jan-04 04:15 UTC
[rspec-users] How to spec a controller method that involves an rjs redirect
On Fri, Jan 2, 2009 at 11:01 AM, Nasir Jamal <nas35_in at yahoo.com> wrote:> > What is the best way to spec a controller method that involves an rjs > redirect? Something like thisConsider: 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 at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org