title: friendly_id and rspec controller tests, finding the correct id
body: <p>I have a simple rspec controller test for basic crud functions. I've recently added Friendly_id to my controller - now all the tests are failing. </p>
  
  <pre><code>describe "PATCH update" do
  
        context "where the record is found" do 
          before do
            allow(model).to receive(:find).and_return(instance)
          end
  
          context "where the record is a root" do 
            before do 
              allow(instance).to receive(:root?).and_return(true)
            end
  
            context "where the record is updated" do
              before do
                allow(instance).to receive(:save).and_return(true)
                patch :update, instance.slug
              end
  
              it "should set a flash notice" do 
                flash[:notice].should_not be_nil
              end
  
              it "should redirect to panel page" do 
                response.should redirect_to(admin_corporate_pages_path)
              end
            end
          end
        end
      end  
  </code></pre>
  
  <p>all of which fail with the following error,</p>
  
  <pre><code> 1) Admin::CorporatePagesController for authenticated users GET edit returns http success
       Failure/Error: get :edit, id: corporate_page
       NoMethodError:
         undefined method `friendly' for #&lt;Class:0x007f993a956b88&gt;
  
  
    2) Admin::CorporatePagesController for authenticated users PATCH update where the record is found where the record is a root where the record is updated should set a flash notice
       Failure/Error: patch :update, instance.slug
       ActionController::UrlGenerationError:
         No route matches {:action=&gt;"update", :controller=&gt;"admin/corporate_pages"}
  </code></pre>
  
  <p>this is the relevant controller,</p>
  
  <pre><code>  def update
      if @corp_page
        @path = (@corp_page.root? ? admin_corporate_pages_path : admin_corporate_page_path(@corp_page.root))
        if @corp_page.update_attributes(params[:corporate_page]) 
          flash[:notice] = 'Page updated'
          redirect_to @path and return 
        else
          flash[:error]= 'There was an error'
          render :new and return
        end
      else
        flash[:error] = "Record not found"
      end
      redirect_to admin_corporate_pages_path
    end
  
    private
      def get_corp_page
        @corp_page = CorporatePage.friendly.find(params[:id])
      end  
  </code></pre>
  
  <p>I don't see how it could make a difference seeing as friendly id uses the :id function anyway. How could it have made such a difference to the tests?</p>