ruby-on-rails – ActiveRecord :: RecordNotFound用于在’js:t
发布时间:2020-12-17 02:46:00 所属栏目:百科 来源:网络整理
导读:尝试在简单的功能规范中使用 javascript,但我甚至无法访问该页面. describe "DiskFiles" do ... describe "update action",js: true do before(:each) do df = FactoryGirl.create(:disk_file) visit edit_disk_file_path(df) end it "should not show check
尝试在简单的功能规范中使用
javascript,但我甚至无法访问该页面.
describe "DiskFiles" do ... describe "update action",js: true do before(:each) do df = FactoryGirl.create(:disk_file) visit edit_disk_file_path(df) end it "should not show checkmark if no match" do expect(page).to_not have_content "?" end end end 我收到此错误: 1) DiskFiles update action should not show checkmark if no match Failure/Error: Unable to find matching line from backtrace ActiveRecord::RecordNotFound: Couldn't find DiskFile with id=7598 [WHERE "disk_items"."type" IN ('DiskFile')] # ./app/controllers/disk_files_controller.rb:89:in `set_disk_file' 这让我感到困惑,因为我刚刚在之前创建了该记录(:每个),当我删除js:true时它就会通过. 我错过了什么? 解决方法
看起来您正在使用事务夹具运行测试.当您使用js:true运行测试时,它将运行您的应用程序并在单独的线程中进行测试.您可以在测试线程中的事务中创建disk_file对象(在测试结束时自动回滚).通常,除非提交(不会发生),否则您的应用程序将无法看到此事务中所做的更改.
此问题的解决方案是为JavaScript测试使用不同的数据库清理策略. database_cleaner宝石是流行的方式来做到这一点. 另见https://github.com/jnicklas/capybara#transactions-and-database-setup (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |