0
我嘗試測試更新功能的控制器類:控制器test_should_update:參數是丟失或爲空值
require 'test_helper'
class AppointmentsControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
include Warden::Test::Helpers
setup do
@heikoAppointment = appointments(:appointment_heiko)
@heiko = users(:user_heiko)
end
test "should update appointment" do
login_as(@heiko)
@heiko.confirmed_at = Time.now
patch appointment_url(@heikoAppointment), params: { appointment: { } }
assert_redirected_to appointment_url(@heikoAppointment)
end
但是我得到這個錯誤:
ActionController::ParameterMissing: param is missing or the value is empty: appointment
在夾具我救一些數據約會:
appointment_heiko:
user: user_heiko
appointed: <%= Time.now + 2.weeks %>
processed: <%= Time.now - 1.weeks %>
shopping_list: shopping_list_lebensmittel
shopper: user_shopper
status: <%= Appointment.statuses[:finished] %>
是否有人知道我可以從這些燈具容易的數據發送PARAMS因此次在我沒有得到這個錯誤了?我是一個初學者,任何代碼都可以幫助!
作爲一個邊評論:堅持[命名規則](https://github.com/bbatsov/ruby-style-guide)命名變量時。對你的同事和名字變量也很好,不需要評論。 – max
非常感謝!但是當我測試should_create_appointment時,如何傳遞所有屬性?這不工作:post appointments_url,params:{約會:{@ heikoAppointment.attributes}} – Peter
'約會:@ heikoAppointment.attributes'。丟失括號作爲'.attributes'返回一個散列。 – max