我的表单接受名为“Item”的对象的id。使用AJAX将id号发送到控制器并且应该返回该项,但是控制器发回错误,说它找不到该项,即使我刚用“let”命令创建它。这是测试:
describe "Manually creates a new clearance_batch", type: :feature do
let!(:wholesale_price) { 100 }
let!(:item) { FactoryGirl.create(:item, style: FactoryGirl.create(:style, wholesale_price: wholesale_price)) }
it "should successfully create a new batch", js: true, :focus => true do
item.reload
visit "/clearance_batches/new"
within('.table_body') do
expect(page).to_not have_content(item.id)
end
element = find('.new_item_box')
element.set(item.id)
click_button 'scan'
end
end
这是错误:
Failures:
1) Manually creates a new clearance_batch should successfully create a new batch
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::RecordNotFound:
Couldn't find Item with 'id'=1
# ./app/controllers/items_controller.rb:18:in `show'
Finished in 2.96 seconds (files took 1.54 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/features/clearance_batches_spec.rb:96 # Manually creates a new clearance_batch should successfully create a new batch
stitchfix-take-home-challenge [capybara-round-2] :>