UserOption中枚举'chat_send_shortcut'的未声明属性类型

我尝试运行 rspec 插件时遇到了这个错误:

似乎是在这里引入的:

可能缺少 base.attribute :chat_send_shortcut, :integer, default: 0

我在添加一个新的枚举时遇到了同样的问题。事实证明,我必须为测试环境明确运行插件迁移:
RAILS_ENV=test LOAD_PLUGINS=1 bin/rails db:migrate

2 个赞

哦,有意思。我以为 db:migrate 默认会包含插件。
确实,我在 RAILS_ENV=test 上有相当多的迁移等待插件。
错误现在消失了,谢谢!

编辑:
实际上,如果你使用 RAILS_ENV=test bin/rake db:migrate,注意“bin/”,它确实会将 LOAD_PLUGINS 设置为 1。

image

你可以看到 bin/rake 的内容:

if ENV['RAILS_ENV'] == 'test' && ENV['LOAD_PLUGINS'].nil?
  if ARGV.include?('db:migrate') || ARGV.include?('parallel:migrate')
    STDERR.puts "You are attempting to run migrations in your test environment and are not loading plugins, setting LOAD_PLUGINS to 1"
    ENV['LOAD_PLUGINS'] = '1'
  end
end

我可能在某个时候因为懒惰而停止输入 bin/ :grinning_face_with_smiling_eyes:

3 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.