0
오이 및 중첩 속성이있는 문서를 업로드하는 테스트를하고 있습니다. 현재, 레일 서버에서 실행할 때 업로드가 잘되지만, capybaras로 결과를 테스트하려고 할 때 실패 할 것입니다. 여기 내 관련 코드는양식을 제출할 때 오이가 nested_attributes를 표시 할 수 없습니다.
오류 메시지
Then I should see the job posted and both files attached # features/step_definitions/job_steps.rb:40
expected there to be content "test_doc"
기능
Background:
Given I am logged in
And I am on the post a new job page
Scenario: User can post a job with a document and picture attached
When I post a job with a picture and document attached
Then I should see the job posted and both files attached
단계 정의
When /^I post a job with a picture and document attached$/ do
fill_in 'Title', with: "Title"
fill_in 'Description', with: "Description"
fill_in 'Value', with: '199.99'
fill_in 'job_job_documents_attributes_0_name', :with => "test_doc"
attach_file('job_job_documents_attributes_0_document', File.join(Rails.root, 'features', 'upload_files', 'test.pdf'))
fill_in 'job_job_documents_attributes_0_name', with: "test_pic"
attach_file('job_job_pictures_attributes_0_picture', File.join(Rails.root, 'features', 'upload_files', 'test.jpg'))
click_button 'Create Job'
Then /^I should see the job posted and both files attached$/ do
page.should have_content 'Job Created!'
page.should have_content 'test_doc' <------ FAILING LINE
end
양식
<%= form_for @job, :html => {name: 'job_form'} do |f| %>
<%= f.label :title %> <br />
<%= f.text_field :title %>
<%= f.label :description %> <br /><br />
<%= f.text_area :description %>
<%= f.label :value %><br />
<%= f.text_field :value %>
<%= f.fields_for :job_documents do |document| %>
<%= document.label :document %>
<%= document.file_field :document %>
<%= document.label :name %>
<%= document.text_field :name %>
<% end %>
<%= f.fields_for :job_pictures do |picture| %>
<%= picture.label :picture %>
<%= picture.file_field :picture %>
<%= picture.label :name %>
<%= picture.text_field :name %>
<% end %>
<%= f.submit %>
<% end %>
0123입니다
페이지 소스는
<p>
<label for="job_job_documents_attributes_0_document">Document</label>
<input id="job_job_documents_attributes_0_document" name="job[job_documents_attributes][0][document]" type="file" />
</p>
<p>
<label for="job_job_documents_attributes_0_name">Name</label>
<input id="job_job_documents_attributes_0_name" name="job[job_documents_attributes][0][name]" size="30" type="text" />
</p>
</p>
그래서 내 모든 비 중첩 된 속성은 오류를 던지는 것이 아니라 내 중첩 된 속성을 볼 카피 바라를 얻을 수없는 것. 어떤 아이디어? 당신은 또한 job_documents_attributes attr_accessible에 추가 모델에 잊지 말고이
@job = Job.new
@job.job_documents.build
처럼 job_documents을 구축하는 데 필요한 새로운 방법의 컨트롤러에서
당신에게 모델이 실제로 만들어있어 확실 ? –