Topic: rspec has_and_belongs_to_many in controller error

I am trying to test this action in a controller

  def associate
    @organisation = Organisation.find(params[:id])
    @geo_physicals_associated = @organisation.geo_physicals
    @geo_physicals = GeoPhysical.all
    @geo_physical = GeoPhysical.new
    @geo_to_associate = GeoPhysical.find(params[:geo_physical][:id])
   
    # check exceptions here
    begin
      @organisation.geo_physicals << @geo_to_associate if !@geo_to_associate.blank?
      flash[:notice] = 'Geo physical saved'
    rescue
      flash[:notice] = 'Geo physical already present' 
    end
   
    render :action => 'edit'
  end


My rspec test is the following:

  describe "POST associate" do

    describe "with valid params" do
      it "associate an organisation to a geophysical" do
        Organisation.stub!(:find).with("11").and_return(mock_organisation())
        GeoPhysical.stub!(:find).with("37").and_return(mock_geo_physical)
        post :associate, :organisation => {:id => "11"}, :geo_physical => {:id => "11"}
      end
    end
     
  end

Any idea?

Last edited by rtacconi (2010-10-24 15:09:36)