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