1
所以,我一直在毆打我的頭一陣子,只是不能取得任何進展。Mongoid和RSpec的ID問題
我有以下的控制器動作:
def create
@job = Job.new(params[:job])
respond_to do |format|
if @job.save
flash[:notice] = "The Job is ready to be configured"
format.html { redirect_to setup_job_path(@job.id) }
format.json { head :ok }
else
format.html { redirect_to new_job_path, notice: 'There was an error creating the job.' }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
我試圖測試這個動作。這是我對成功創建重定向的測試。
let (:job) { mock_model(Job).as_null_object }
我不斷收到以下錯誤:
it "redirects to the Job setup" do
job.stub(:id=).with(BSON::ObjectId.new).and_return(job)
job.stub(:save)
post :create
response.should redirect_to(setup_job_path(job.id))
end
工作是整個套件這裏定義
2) JobsController POST create when the job saves successfully redirects to the Job setup
Failure/Error: response.should redirect_to(setup_job_path(job.id))
Expected response to be a redirect to <http://test.host/jobs/1005/setup> but was a redirect to <http://test.host/jobs/4ea58505d7beba436f000006/setup>
我已經嘗試了一些不同的東西,但不管我嘗試我似乎無法在我的測試中得到正確的對象ID。
謝謝!我是rspec新手,似乎忘記了分配。 – LeakyBucket