मैं अपने रुपेक नियंत्रक परीक्षणों में एसोसिएशन का परीक्षण करने की कोशिश कर रहा हूं। समस्या यह है कि कारखाने attributes_for कमांड के लिए संघों का उत्पादन नहीं करता है। तो, this post में सुझाव निम्नलिखित मैं अपने सत्यापित करें ताकि तरह मेरे नियंत्रक कल्पना में जिम्मेदार बताते हैं परिभाषित:फैक्टरीगर्ल विशेषताएँ और संघ
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
फिर भी:
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
हालांकि
, जब नियंत्रक परीक्षण रन मैं अभी भी निम्न त्रुटियों मिल टर्मिनल में valid_attributes उत्पादन स्पष्ट रूप से पता चलता प्रत्येक valid_attribute एक user_id, country_id है और विशेषज्ञ सही पर सेट किया जाता है कि:
{:id=>nil, :user_id=>2, :country_id=>1, :client=>true, :expert=>false, :created_at=>nil, :updated_at=>nil}
आह धन्यवाद - आज रात बहुत लंबे समय तक काम कर रहा है! –