【问题标题】:How to add pages to Refinery CMS testing dummy app database如何将页面添加到炼油厂 CMS 测试虚拟应用程序数据库
【发布时间】:2014-02-10 01:38:24
【问题描述】:

我在 the extension guidethe extension testing guide 之后创建了 Refinery CMS 扩展。

一些 rspec 单元测试通过并且http://localhost/the_extension 在网络浏览器中加载。但现在测试失败了,因为虚拟应用没有页面(或任何其他数据库表)。

我尝试将 dummy_dev 文件复制到 dummy_test(以及一堆其他东西),并且 有效(有点),因为当我运行虚拟应用程序 (cd spec/dummy; rvmsudo rails s -p 80 -e test) 时,页面在我的浏览器中加载,当我查询页面表(sqlite3 dummy_test 'select * from refinery_pages;)时,有页面。

但每次我运行 cd vendor/extensions/the_extension; bundle exec rake spec 时,它都会删除页表中的所有条目。

我尝试将此添加到spec/spec_helper.rb

# Copy the prototype test database to the test database.
FileUtils.cp File.expand_path('../dummy_test_db_prototype', __FILE__), File.expand_path('../dummy/dummy_test', __FILE__)

但在运行规范时,测试数据库已被删除。读入规范后删除数据库,因为如果我将以下内容放在spec/features/refinery/the_extension/the_extension_spec.rb 的底部,则数据库仍然有页面:

# DEBUG
puts 'Querying test db:'
system "sqlite3 /some_app/vendor/extensions/the_extension/spec/dummy/dummy_test 'select * from refinery_pages;'"
puts 'Done querying.'

如何确保测试运行时测试数据库中有页面?

【问题讨论】:

    标签: ruby-on-rails rspec refinerycms


    【解决方案1】:
    describe "stuff" do
      it "should do stuff" do
        before { Refinery::Page.create([{ title: 'home', link_url: '/' }]) }
    
        ...
      end
    end
    

    【讨论】:

    • 我认为这行得通。不幸的是,我仍然遇到同样的错误:Capybara::Webkit::InvalidResponseError: Unable to load URL: http://myapp.com/ because of error loading http://myapp.com/: Unknown error。这部分是由前端的window.location.href = target_domain 引起的。我读到我不应该尝试用 Capybara 进行 API 测试,事实证明这是真的。
    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多