我正在用 rspec 进行测试
我有这个功能参数:
def update_section_params
params.require(:section).permit(:type_id, :by_team)
end
我正在使用更新部分
if @section.update(update_treatment_params)
如果 by_team: nil
我会收到这个错误PG::NotNullViolation: ERROR: null value in column
我怎样才能在我的测试中发现这个错误?
payload = { by_team: nil }
put ".../.../sections/#{@section1['id']}", params: payload
在你的
Section
模型中(可能在app/models/section.rb
。添加一个belongs_to
和验证:
class Section < ApplicationRecord
belongs_to :type
validates :by_team, presence: true
end