无法在Rspec中调用控制器操作

时间:2016-05-06 13:41:37

标签: ruby-on-rails ruby mongodb rspec

我一直在尝试为名为“Estimate controller”的Controller实现RSpec,以测试我的邮件功能(发送估计)是否正常工作。但是我无法从我的RSpec调用控制器动作。我需要在哈希中设置一些值(to,subject,message,cc,current_user,attachments)并将该哈希值发送到Estimate controller.Here就是我试过的..

estimates_controller_spec.rb

    describe "post 'send_estimate'" do
          it "should send estimate " do
              @estimate = Fabricate(:estimate, id:  Faker::Number.number(10), validity: "12/12/2014", total_value: 1222.00, user_id:@user.id, project_id: @project_id)
est_params = {
          to: "rspec@rails.com",
          subject: "Estimate",
          message: "Check out the Estiamte details",
          cc: "respec@rails.com",
          current_user: @user,
          attachments: ""
        }
           expect{
      post :send_estimate, estimate: est_params
      }.to change { ActionMailer::Base.deliveries.count }.by(1)

      end 
    end

estimates_controller.rb

def send_estimate 
    respond_to do |format|
      if @estimate.send_email(params[:to], params[:subject], params[:message], params[:cc], current_user, params[:attachments])
        @estimate.create_activity :send_estimate, owner: current_user, recipient: @estimate.project
        format.html  { redirect_to lead_path(@estimate.project), notice: "Email sent Successfully"}        
        format.json { head :no_content, status: :ok}
      else
        format.json { render json: @estimate.errors }
        format.html { redirect_to contacts_path, notice: 'Something went wrong' }
      end      
    end       
  end

0 个答案:

没有答案