2

Project模型中:

has_and_belongs_to_many :subprojects,
  :join_table => "project_projects"

在 Cucumber 功能文件中:

Given the following projects exist:
| name   | type |
| first  | foo  |
| second | bar  |
| third  | baz  |
| fourth | bar  |
Given the following subprojects exist:
| subproject | superproject |
| first      |              |
| second     | first        |
| third      | first        |
| third      | second       |
...
And I add a superproject "second" to "fourth"
And I add a superproject "third" to "fourth"

换句话说,third两个父级,first并且secondfourth最初没有父级,但是为了单个场景的目的添加了一些父级。我们如何在 Factory Girl Rails 中为此创建工厂?我们已经有一个:project工厂,但是没有Project_project模型,原因很明显,而且我们显然不想在每次添加关系时都创建新项目——我们需要重用子项目<->超级项目工厂中的现有对象。

4

0 回答 0