Tôi đang cố kiểm tra các kết hợp trong các kiểm tra bộ điều khiển Rspec của mình. Vấn đề là Nhà máy không sản xuất các hiệp hội cho lệnh attributes_for. Vì vậy, sau khi đề nghị trong this post tôi xác định Validate của tôi thuộc tính trong tôi đặc tả bộ điều khiển như vậy:Thuộc tính FactoryGirl_for và các liên kết
def valid_attributes
user = FactoryGirl.create(:user)
country = FactoryGirl.create(:country)
valid_attributes = FactoryGirl.build(:entitlement, user_id: user.id, country_id: country.id, client: true).attributes.symbolize_keys
puts valid_attributes
end
Tuy nhiên, khi chạy thử nghiệm điều khiển tôi vẫn nhận được các lỗi sau đây:
EntitlementsController PUT update with valid params assigns the requested entitlement as @entitlement
Failure/Error: entitlement = Entitlement.create! valid_attributes
ActiveRecord::RecordInvalid:
Validation failed: User can't be blank, Country can't be blank, Client & expert are both FALSE. Please specify either a client or expert relationship, not both
Tuy nhiên, các đầu ra valid_attributes trong terminal hiển thị rõ ràng rằng mỗi valid_attribute có user_id, country_id và expert được đặt thành true:
{:id=>nil, :user_id=>2, :country_id=>1, :client=>true, :expert=>false, :created_at=>nil, :updated_at=>nil}
Xin cảm ơn - đã làm việc trong đêm nay quá lâu! –