问题单的HTML代码
<%= simple_nested_form_for @issue_slip do |f| %>
<%= f.error_messages %>
<p>
<%= f.hidden_field :user_id, :value => current_user.id %>
<b>From Store:</b></br>
<%= f.label :store_location_id %>
<% if !current_user.store_location_id? %>
<%= f.collection_select :store_location_id, StoreLocation.all,:id,:name, {:prompt => "Select Store"}, :style => 'width:205px;' %><br />
<% else %>
<%= f.collection_select :store_location_id, StoreLocation.all,:id,:name, :value => current_user.store_location_id %><br/>
<% end %>
<b>Delivery To:</b></br>
<% if @count == nil %>
<div class = "shop_floors">
<%= f.label :shop_floor_id %>
<%= f.collection_select :shop_floor_id, ShopFloor.all,:id,:name, {:prompt => "-Select a Shopfloor"}, :style=>'width:150px;'%></div><br/>
<% else %>
<strong><%= f.label :shop_floor_id %>:<%= @issue_slip.shop_floor.name %></strong><br /><% end %>
<div class ="date">
<%= f.label :date, "Date" %>
<%= f.datepicker :date, :dateFormat => 'dd MM, yy', :showOn => "both", :buttonImage => "/assets/calendar.gif", :buttonImageOnly => true, :changeMonth => true, :changeYear => true , :size =>20 %><br/></div>
<%= f.label :project_id %>
<%= f.text_field :project_id , :size => 20 %><br />
<%= f.label :employee_id, "Issued. By" %>
<% if !current_user.employee_id? %>
<%= f.collection_select :employee_id, Employee.all,:id,:name, {:prompt => "Select Employee"}, :style => 'width:205px;' %><br />
<% else %>
<%= f.collection_select :employee_id, Employee.find_all_by_user_id(current_user.id), :id, :name %><br/>
<% end %>
<%= f.input :remarks, :label => 'Remarks', :input_html => { :size => 20} %><br/>
<%= f.label :bom_quantity %>
<%= f.text_field :bom_quantity, :size=> 20, :value => number_with_precision(f.object.bom_quantity , :precision => 3) %><br />
<div class = "cust_order">
<%= f.label :customer_order_id %>
<%= f.collection_select :customer_order_id , CustomerPendingOrder.all, :id,:id, :prompt => "Select Customer Order" %></div> <br />
<div class = "bom">
<%= f.label :bill_of_material_id %>
<%= f.collection_select :bill_of_material_id, BillOfMaterial.all, :id, :title , :prompt => "Select a BOM", :style => 'width:205px;' %></div>
<div class="load_bom"><%= f.submit "Load BOM" %></div> <br/>
<hr>
<%= f.fields_for :issue_slip_line_items do |builder| %>
<%= render 'issue_slip_line_item_fields', :f => builder %>
<%end%>
<p><%= f.link_to_add "Add Product", :issue_slip_line_items %> </p>
<p><%= f.submit data: {:disable_with=>@submit_tag_label}%><div class="load_preview_issue_slip"><%= f.submit "preview", :style => 'width:130px;', data: {:disable_with=>"loading preview..."} %></div></p>
<% end %>
</p>
发放单行项目
<%= f.link_to_remove "Remove Product"%><br/>
<div class ="product">
<%= f.association :product, :prompt =>"Select Product", input_html: {data:{prices: prices}}, :collection => Product.in_stock %> </div>
<%= image_tag :image , :class => "prodimage"%>
<div class = "productid">
<%= f.hidden_field :product_id, :class=>"productid" %></div>
<br/>
<div class ="price"><%= f.label :price %><%= f.text_field :price, :size=>20, :value => number_with_precision(f.object.price, :precision => 2)%> </div><br/>
<div class = "qty">
<%= f.label :quantity, "Quantity"%>
<%= f.text_field :quantity, :size=>20 , :value => number_with_precision(f.object.quantity, :precision => 3)%></div><br/>
<%= f.label :amount %>
<%= f.text_field :amount, :size=>20,:class =>"amt", :value => number_with_precision(f.object.amount, :precision => 2) %><br/>
<!--%= f.label :customs_duty, "Custom Duty"%-->
<!--%= f.text_field :customs_duty, :size=>20 %-->
</div>
<hr/>
创建测试用例 issue_slips_spec.rb
it "issue slips test", :js => true do
click_link 'New Issue Slip'
select('Inuit HAL', :from => 'Store location')
expect{ page.should have_content 'New Issue Slip'}
expect{ page.should have_content 'From Store'}
expect{ page.should have_content 'Delivery To'}
select('sample shopfloor', :from => 'Shop floor')
expect{ page.should have_content 'Shop floor '}
fill_in "Date", :with => "06 October, 2014"
fill_in "Project", :with => "1993"
select('Sample Employee', :from => 'Issued. By')
fill_in "Remarks", :with => "There is no remarks to mention"
fill_in "Bom quantity", :with => "2"
expect{ page.should have_link 'Add Product'}
click_link 'Add Product'
select('Nike', :from => 'Product')
fill_in "Price", :with => "1000"
fill_in "Quantity", :with => "1"
fill_in "Amount", :with => "1000"
expect{ page.should have_link 'Back to List'}
click_button 'Create Issue slip'
end
end
错误讯息:
Failures:
1) Sign in issue slips test
Failure/Error: select('Nike', :from => 'Product')
Webrat::NotFoundError:
Could not find field: "Product"
# ./spec/requests/issue_slips_spec.rb:36:in `block (2 levels) in <top (required)>'
Finished in 47.31 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/issue_slips_spec.rb:15 # Sign in issue slips test
在上面的代码中,添加产品链接是我点击该链接的问题,它应该加载另一个名为issue_slip_line_item的表单,我的产品,价格,金额,数量字段在我的情况下测试无法识别产品领域它给我的错误无法找到产品,实际上当我点击添加产品链接时,它应该打开问题单行项目表单,在那里我有一个测试用例未能打开链接的字段请帮助< / p>