Этот тест создания POST не работает. Он должен перенаправлять на report_path, но он не работает.Rspec POST Test не проходит. Ожидаемый ответ должен быть <3XX: redirect>, но был 200
describe "POST #create" do
let(:report) { assigns(:report) }
let(:test_option) { create(:option) }
let(:test_student) { create(:student) }
context "when valid" do
before(:each) do
post :create, params: {
report: attributes_for(:report, student: test_student,
report_options_attributes: [build(:report_option).attributes]
)
}
end
it "should redirect to reports_path" do
expect(response).to redirect_to reports_path
end
Мои PARAMS настроены так:
def report_params
params.require(:report).permit(:student,
report_options_attributes: [:id, :option, :note, :_destroy]
)
end
Контроллер:
def create
@report = Report.new(report_params)
if @report.save
redirect_to reports_path
else
render :new
end
end
Доклад модель:
class Report < ApplicationRecord
belongs_to :student, dependent: :delete
has_many :report_options, dependent: :destroy
accepts_nested_attributes_for :report_options, allow_destroy: true
end
ReportOption модель:
class ReportOption < ApplicationRecord
belongs_to :option
belongs_to :report, optional: true
end
Я передаю правильные Params в тесте, но я действительно не знаю, что происходит не так ..
Несомненно, я также разместил модели, которые я использую – Thatsthati
Sure @ArunKumar – Thatsthati
Думаю, ваш тест не создает объект 'report'. Таким образом, он снова отображает «новый», который составляет 200, а не перенаправление. –