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

Steve Tooke steve.tooke at gmail.com
Thu Nov 30 09:17:01 EST 2006


in Spec::Rails::ControllerInstanceMethods we have this method:

      def render(options=nil, deprecated_status=nil, &block)
        unless block_given?
          unless integrate_views?
            @template = Spec::Mocks::Mock.new("mock template")
            @template.stub!(:evaluate_assigns)
            @template.stub!(:render)
            @template.stub!(:file_exists?).and_return(true)
            @template.stub!(:full_template_path)
            @template.stub!(:render_file)
            @template.stub!(:render_partial)
          end
        end
        render_matcher.set_actual(ensure_default_options(options),
response, &block)
        super
      end

This seems to sub the render methods, and not return anything, by
changing the :render_file stub to return true it solves my problem...
the real ActionController::Base#rende_file returns the response body,
so I'm not sure that simply setting this to return true is ideal?

Steve

On 11/30/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 11/30/06, Steve Tooke <steve.tooke at gmail.com> wrote:
> > Could this be because I'm isolating the controllers from the views, so
> > nothing is actually being rendered - hence why render is returning
> > nil?
>
> Could be. I haven't had a look at this yet, but that sounds plausible.
>
> >
> > On 11/29/06, Steve Tooke <steve.tooke at gmail.com> wrote:
> > > Submitted as Bugs item #6959
> > >
> > > I'm trying to have a crack at fixing this, but I'm not sure exactly
> > > where I should be looking, I'm guessing its in the controller context?
> > >
> > > Cheers,
> > > Steve
> > >
> > > On 11/29/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> > > > Would you please submit this directly to the tracker?
> > > >
> > > > http://rubyforge.org/tracker/?group_id=797
> > > >
> > > > Thanks,
> > > > David
> > > >
> > > > On 11/29/06, Steve Tooke <steve.tooke at gmail.com> wrote:
> > > > > 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
> > > > > _______________________________________________
> > > > > rspec-devel mailing list
> > > > > rspec-devel at rubyforge.org
> > > > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > > > >
> > > > _______________________________________________
> > > > rspec-devel mailing list
> > > > rspec-devel at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > > >
> > >
> > _______________________________________________
> > rspec-devel mailing list
> > rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
> >
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list