【问题标题】:ActiveRecord::Fixture::FixtureError: table "posts" has no column named "user" - where a 'post' belongs_to 'user'ActiveRecord::Fixture::FixtureError: 表“posts”没有名为“user”的列 - 其中“post”属于“user”
【发布时间】:2017-08-21 10:33:04
【问题描述】:

我正在尝试为具有belongs_to 关联的类创建一些关联测试。

在创建固定装置时测试失败 - Rails 未检测到 Posts 中的 belongs_to :user 关联。

它似乎传递了常规的rake test 命令,但不是当单个文件在guard 中运行时。

测试如下:

module Post
  class AssociationsTest < ActiveSupport::TestCase
    subject { Post.new }
    should belong_to(:user)
  end
end

【问题讨论】:

    标签: ruby-on-rails activerecord guard belongs-to


    【解决方案1】:

    我设法找出了我的问题 - 我认为这是因为我在测试中使用了嵌套的模块/类定义,并且使用了相同的模块名称。

    工作代码是:

    class Post::AssociationsTest < ActiveSupport::TestCase
      subject { Post.new }
      should belong_to(:user)
    end
    

    【讨论】:

      猜你喜欢
      • 2023-02-06
      • 2023-03-20
      • 2017-03-07
      • 1970-01-01
      • 2016-10-01
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多