回答編集履歴
1
追記
answer
CHANGED
@@ -8,4 +8,34 @@
|
|
8
8
|
p @comment # commentは作られているか
|
9
9
|
p @comment.errors # エラーは起きていないか
|
10
10
|
end
|
11
|
-
```
|
11
|
+
```
|
12
|
+
|
13
|
+
### 追記
|
14
|
+
|
15
|
+
[factory_bot/issues/1255](https://github.com/thoughtbot/factory_bot/issues/1255#issuecomment-462190490)
|
16
|
+
|
17
|
+
????に書いてあるとおり、
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
FactoryBot.define do
|
21
|
+
factory :comment do
|
22
|
+
profile #<= buildしたときに生成されない
|
23
|
+
post{ create(:post, profile: profile) }
|
24
|
+
text "hogehoge"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
ようなので、上記Issueにあるように `FactoryBot.use_parent_strategy = false` を設定するか
|
30
|
+
|
31
|
+
```Ruby
|
32
|
+
FactoryBot.define do
|
33
|
+
factory :comment do
|
34
|
+
profile { create(:profile) }
|
35
|
+
post{ create(:post, profile: profile) }
|
36
|
+
text "hogehoge"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
のようにする必要がありそうです。
|