【发布时间】:2015-12-04 04:53:46
【问题描述】:
我很难通过考试:
错误:
Failure/Error: post :create, { appointment: { dentist_id: '1', patient_id: '2', appt_date: '2015-12-05 09:00:00' } }
ActiveRecord::RecordNotFound:
Couldn't find Dentist with 'id'=
约会控制器:
def create
@dentist = Dentist.find(params[:dentist_id])
@appointment = @dentist.appointments.new(appointment)
if Appointment.exists?(:appt_date => @appointment.appt_date)
render :new
else
@appointment.save
redirect_to dentist_path(@dentist)
end
end
预约说明:
describe 'POST #create' do
it 'assigns a newly created appointment as @appointment' do
post :create, { appointment: { dentist_id: '1', patient_id: '2', appt_date: '2015-12-05 09:00:00' } }
expect(assigns(:appointment)).to be_a(Appointment)
expect(assigns(:appointment)).to be_persisted
end
end
我错过了什么?非常感激任何的帮助。
【问题讨论】:
标签: ruby-on-rails ruby activerecord rspec