为什么需要在Rails中迁移测试数据库?

ardavis

创建新的迁移文件后,运行迁移,然后运行测试,我收到:

Failure/Error: ActiveRecord::Migration.maintain_test_schema!

ActiveRecord::PendingMigrationError:

  Migrations are pending. To resolve this issue, run:

          bin/rails db:migrate RAILS_ENV=test

以下代码片段不是rails_helper.rb应该为我将迁移应用于测试数据库吗?

# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

更新资料

这是我的config/environments/test.rb要求:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Do not eager load code on boot. This avoids loading your whole application
  # just for the purpose of running a single test. If you are using a tool that
  # preloads Rails for running tests, you may have to set it to true.
  config.eager_load = false

  # Configure public file server for tests with Cache-Control for performance.
  config.public_file_server.enabled = true
  config.public_file_server.headers = {
    'Cache-Control' => 'public, max-age=3600'
  }

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates.
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment.
  config.action_controller.allow_forgery_protection = false
  config.action_mailer.perform_caching = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end
sa77

在运行测试时,将按以下顺序加载配置(除非您在rails应用程序中自定义了autoload_paths的顺序):

  1. config / application.rb
  2. 配置/环境/test.rb
  3. spec / rails_helper.rb

所以,你收到的迁移挂起的误差必定是由于config.active_record.migration_error = true之前在铁轨上的发动机负荷此配置设置的地方rails_helper.rb,其中ActiveRecord::Migration.maintain_test_schema!指令定义。

尝试config.active_record.migration_error = falseconfig / environments / test.rb上进行设置以跳过迁移检查,如rspec升级指南中所述

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

创建测试数据库时禁用Django中的数据迁移

来自分类Dev

将装置迁移到Django测试数据库

来自分类Dev

Yii 2迁移测试数据库

来自分类Dev

运行迁移会破坏测试数据库中的所有视图

来自分类Dev

为什么需要在我们的应用程序中刷新数据库视图?

来自分类Dev

为什么我的Django工厂功能会在本地数据库中创建模型,而不是在测试数据库中创建模型?

来自分类Dev

Django测试数据库需要启用Postgres Extension

来自分类Dev

Mongo:show dbs不显示测试数据库。为什么?

来自分类Dev

为什么 FactoryBot 不在测试数据库中保存密码?

来自分类Dev

Django为什么不实际编写更改以测试数据库

来自分类Dev

Rails:如何确保测试数据库的干净状态?

来自分类Dev

Rails - 所有测试数据库操作挂起

来自分类Dev

rspec rails:单元测试数据库查询

来自分类Dev

为什么要在数据库中创建视图?

来自分类Dev

如何在Rails 5中为测试数据库运行db:migrate?

来自分类Dev

如何在 dockerized Rails 应用程序中创建 Mysql 测试数据库?

来自分类Dev

在Rails中测试数据库种子文件的有效性

来自分类Dev

为什么Rails 4测试不会重置数据库

来自分类Dev

受限环境中的Django测试数据库

来自分类Dev

如何测试数据库中是否存在行

来自分类Dev

在 django 中测试数据库而不是 django 模型

来自分类Dev

如何在Go中测试数据库错误?

来自分类Dev

在Vapor 3中删除测试数据库

来自分类Dev

为什么需要在在线购物数据库的商品类别中添加ID字段?

来自分类Dev

Laravel 5.1-使用SQLite的测试数据库在向下迁移时给出'no such index'错误

来自分类Dev

PostgreSQL在线测试数据库

来自分类Dev

RSpec测试数据库索引

来自分类Python

Django单元测试需要很长时间才能创建测试数据库

来自分类Dev

在AWS RDS中克隆数据库之一以获取测试数据库

Related 相关文章

  1. 1

    创建测试数据库时禁用Django中的数据迁移

  2. 2

    将装置迁移到Django测试数据库

  3. 3

    Yii 2迁移测试数据库

  4. 4

    运行迁移会破坏测试数据库中的所有视图

  5. 5

    为什么需要在我们的应用程序中刷新数据库视图?

  6. 6

    为什么我的Django工厂功能会在本地数据库中创建模型,而不是在测试数据库中创建模型?

  7. 7

    Django测试数据库需要启用Postgres Extension

  8. 8

    Mongo:show dbs不显示测试数据库。为什么?

  9. 9

    为什么 FactoryBot 不在测试数据库中保存密码?

  10. 10

    Django为什么不实际编写更改以测试数据库

  11. 11

    Rails:如何确保测试数据库的干净状态?

  12. 12

    Rails - 所有测试数据库操作挂起

  13. 13

    rspec rails:单元测试数据库查询

  14. 14

    为什么要在数据库中创建视图?

  15. 15

    如何在Rails 5中为测试数据库运行db:migrate?

  16. 16

    如何在 dockerized Rails 应用程序中创建 Mysql 测试数据库?

  17. 17

    在Rails中测试数据库种子文件的有效性

  18. 18

    为什么Rails 4测试不会重置数据库

  19. 19

    受限环境中的Django测试数据库

  20. 20

    如何测试数据库中是否存在行

  21. 21

    在 django 中测试数据库而不是 django 模型

  22. 22

    如何在Go中测试数据库错误?

  23. 23

    在Vapor 3中删除测试数据库

  24. 24

    为什么需要在在线购物数据库的商品类别中添加ID字段?

  25. 25

    Laravel 5.1-使用SQLite的测试数据库在向下迁移时给出'no such index'错误

  26. 26

    PostgreSQL在线测试数据库

  27. 27

    RSpec测试数据库索引

  28. 28

    Django单元测试需要很长时间才能创建测试数据库

  29. 29

    在AWS RDS中克隆数据库之一以获取测试数据库

热门标签

归档