1
現在、レールユニットテストを行っています。ミニテストレールを使用しています。編集可能なブートストラップ付きミニテストレール
私はブートストラップ編集可能なjsを使用して、ビュー内のデータを直接更新しています。
値を正しくアサートできない場合は、失敗の結果が出ます。
ブートストラップ編集可能は、通常のRails更新アクションよりもパラメータを送信するために使用されているためです。
私のコードを見てください。私含まれるモジュールで
def edit_job_type
update_common_table('job_types', params[:pk], params[:name], params[:value])
end
:私minitestレールにおいて
def update_common_table(table, id, key, value)
begin
case table
when 'job_types'
@record = JobType.find(id)
end
case key
when 'en_name'
@record.en_name = params[:value]
edit_field = 'English Name'
end
@record.last_updated_by = session[:username]
@record.save
render json: {
status: 'success',
message: "#{edit_field} was successfully updated.",
updated_at: @record.updated_at.to_time.strftime("%a, %e %b %Y %H:%M"),
updated_by: session[:username]
}
rescue => error
render json: {status: 'error', message: error.message}
end
end
、コントローラ:
私 コントローラで私器具で
setup do @job_type = job_types(:waiter) end test "should update job_type" do patch :edit_job_type, id: @job_type.id, job_type: { pk: @job_type.id, name: 'en_name', value: "janitor" } assert_response :success, message: 'English Name was successfully updated.' @job_type.reload assert_equal "janitor", @job_type.en_name # this one FAILS, not updated value end
>をjob_types:
waiter:
en_name: waiter
私はすくいテスト実行すると:
I got failure result, because the update was failed.
Expected: "New Job Type Updated"
Actual: "waiter"
Still getting the default value "waiter", instead of "janitor"
を、私は私のテストを固定する方法を把握することを助けてください。