[rspec-users] redirect_to(:action => 'foo') and return

David Chelimsky dchelimsky at gmail.com
Sat Dec 30 23:13:04 EST 2006


On 12/30/06, Courtenay <court3nay at gmail.com> wrote:
> I'm not sure why this is happening, but if I do this in a controller
>
>     unless @variation && @variation.quantity > 0
>       flash[:error] = "Sorry, that product is currently not available."
>       redirect_to(:action => 'error') and return
>     end
>
> rspec tells me
>
>   2)
>   ActionController::DoubleRenderError in 'The Carts controller with an
> existing User should add items to the cart'
> Render and/or redirect were called multiple times in this action.
> Please note that you may only call render OR redirect, and only once
> per action. Also note that neither redirect nor render terminate
> execution of the action, so if you want to exit an action after
> redirecting, you need to do something like "redirect_to(...) and
> return". Finally, note that to cause a before filter to halt execution
> of the rest of the filter chain, the filter must return false,
> explicitly, so "render(...) and return false".
> /disk0s3/rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:82:in
> `redirect_to'
> /disk0s3/rails/store/trunk/vendor/plugins/rspec_on_rails/lib/spec/rails/context/controller.rb:82:in
> `redirect_to'
> /disk0s3/rails/store/trunk/config/../app/controllers/carts_controller.rb:92:in
> `create'
> spec/controllers/carts_controller_spec.rb:99:
> spec/controllers/carts_controller_spec.rb:118:
>
>
> however if I change that to
>
>       redirect_to(:action => 'error')
>       return
>
> it works just fine.  All versions of "..and return" seem to fail.

Please raise a bug on this.

http://rspec.rubyforge.org/contribute.html
http://rubyforge.org/tracker/?group_id=797

Thanks,
David

>
>
> courtenay
> http://blog.caboo.se
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list