1
私はしばらく前から頭を打ちましたが、それ以上の進歩はありません。私はこのアクションをテストしようとしていますモンゴイドと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
:
は、私は、次のコントローラのアクションを持っています。成功した作成に向けたリダイレクトのテストです。
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
ジョブがここにスイート全体のために定義されています
let (:job) { mock_model(Job).as_null_object }
私は、次のエラーを取得しておいてください。
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>
私はいくつかの異なるものを試していないが、どんなIました私のテストでは、適切なオブジェクトIDを取得できないようです。
ありがとうございます!私はrspecには新しく、割り当てについて忘れているようだ。 – LeakyBucket