Hi, all.

I am perplexed. The problem I'm having seems to be related to
rendering a "non-standard" view. In our controllers, the 'new' and
'edit' actions share a template, as shown here.

Controller:

  def new
    @location = Location.new

    respond_to do |format|
      format.html { render :template => 'locations/locations' }
      format.xml  { render :xml => @location }
    end
  end

  def edit
    @location = Location.find(params[:id])
    render :template => 'locations/locations'
  end

  def create
    @location = Location.new(params[:location])

    respond_to do |format|
      if @location.save
        flash[:notice] = 'Location was successfully created.'
        format.html { redirect_to(@location) }
        format.xml  { render :xml => @location, :status => :created,
:location => @location }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @location.errors, :status =>
:unprocessable_entity }
      end
    end
  end

  def update
    @location = Location.find(params[:id])

    respond_to do |format|
      if @location.update_attributes(params[:location])
        flash[:notice] = 'Location was successfully updated.'
        format.html { redirect_to(@location) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @location.errors, :status =>
:unprocessable_entity }
      end
   end
end

In the controller spec, the 'new' and 'edit' actions work fine, but
when I try to get the response back for the 'update' and 'create'
actions, I get a failure.

This works:

    it "should render new template" do
      get :new
      response.should render_template('locations/locations')
    end

This fails:

    describe "with failed save" do

      def do_post
        @location.should_receive(:save).and_return(false)
        post :create, :location => {}
      end

      it "should re-render 'new'" do
        do_post
        response.should render_template('locations/locations')
      end

    end


Error:

'LocationsController handling POST /cms/locations with failed save
should re-render 'new'' FAILED
expected "locations/locations", got "locations/new"
./spec/controllers/locations_controller_spec.rb:320:



Any advice is appreciated. Thank you.

- Michele
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to