[rspec-devel] Calls to render and redirect in controllers should return true (rspec-on-rails)

Steve Tooke steve.tooke at gmail.com
Wed Nov 29 10:35:14 EST 2006


Sorry for the duplicate, I managed to send the incomplete email by accident!

I think I've come across a small bug which causes the "do and return"
pattern to fail with render or redirect_to inside an controller
action.

According to changeset 462 (http://dev.rubyonrails.org/changeset/462)
render and redirect_to should both return true, this does not appear
to happen when running specs

e.g.

class MyController < ApplicationController

  def index
    @page = Page.find(:first, :condtions => ['name = ?', params[:name]])
    show_404 and return unless @page
    render :action => :page
  end

  protected
  def show_404
    render( :file => "#{RAILS_ROOT}/public/404.html",
                 :status => "404 Not Found")
  end
end

----------------

context "a GET to index with an unrecognised page" do
  controller_name :my_controller

  setup do
    Page.stub!(:find)
  end

  specify "should not assign a page" do
    get 'index', :name => 'broken'
    assigns['page'].should == nil
  end

  specify "should render 404 file" do
    controller.should_render :file => "#{RAILS_ROOT}/public/404.html",
                                            :status => "404 Not Found"
    get 'index', :name => 'broken'
  end
end

-------------

Both of these specs will fail with an
"ActionController::DoubleRenderError", demonstrating that the return
call is being ignored.

Regards,
Steve


More information about the rspec-devel mailing list