jeudi 30 avril 2015

rspec assigning variables - ERROR: expected: "Completed" got: "pending" (compared using ==)

I am testing my controller in ruby on rails using RSPEC and Factories (using factory girl) Controller Code:

class JobsController < ApplicationController
  before_action :authenticate_member!
  before_action :set_job

def complete
  @job.status = "completed"
  @job.save!
  Event.where("job_id = ? AND starts_at > ?", @job.id, DateTime.now).destroy_all
  redirect_to scheduler_path
  puts @job.inspect
end

  def set_job
    @job = Job.find(params[:id] || params[:job_id])
  end

end

RSPEC Code:

describe JobsController do
  login_user

  before do 
    @job=FactoryGirl.create(:job)
  end

  describe "Complete Action" do 
    it "sets job status to complete" do 
      puts @job.inspect
      get :complete, :id=>@job.id
      @job.status.should eq("Completed")
    end
  end

The Error:

 expected: "Completed" got: "pending" (compared using ==)

Note the output from the controller code is:

#<Job id: 12, name: nil, status: "completed">

So I know its changed within the controller, however why does it go back to "pending" in factory girl ? Note 2: Pending is the default value. Am i mis-understanding the relationship between the controller and factory girl ?

Help please?!

Aucun commentaire:

Enregistrer un commentaire