FactoryBot 最终成为一个 table 文件

FactoryBot end as a table fiel

我在创建一些工厂时遇到问题,当创建数据库时有人调用了 table 的字段,例如 "end" 现在当我尝试构建工厂时,当我键入 end 和然后尝试分配一个值,它将 en 作为工厂的结尾而不是 table.

的属性

知道如何修复它吗?

我认为您正试图在工厂定义中使用 reserved 词作为属性名称。您可以这样做:

factory :enrique_table do
  add_attribute(:end) { 'just the beginning' }
end

add_attribute 方法让您用 reserved 词定义属性。如果您想了解有关 FactoryBot 的更多信息,请前往他们的 Getting Started 指南。

希望对您有所帮助。