質問編集履歴
5
ミス
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
```
|
17
17
|
describe "#create" do
|
18
|
-
let(:params) { { comment:
|
18
|
+
let(:params) { { comment: build(:comment).attributes } }
|
19
19
|
subject {
|
20
20
|
post :create,
|
21
21
|
params: params
|
4
アソシエーションの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -46,14 +46,29 @@
|
|
46
46
|
```
|
47
47
|
FactoryBot.define do
|
48
48
|
factory :comment do
|
49
|
-
|
49
|
+
profile
|
50
|
-
|
50
|
+
post{ create(:post, profile: profile) }
|
51
51
|
text "hogehoge"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
```
|
56
56
|
|
57
|
+
###アソシエーション
|
58
|
+
```
|
59
|
+
class Comment < ApplicationRecord
|
60
|
+
belongs_to :post
|
61
|
+
belongs_to :profile
|
62
|
+
end
|
57
63
|
|
64
|
+
class Post < ApplicationRecord
|
65
|
+
belongs_to :profile
|
66
|
+
end
|
58
67
|
|
68
|
+
class Profile < ApplicationRecord
|
69
|
+
has_many :posts, dependent: :destroy
|
70
|
+
has_many :comments, dependent: :destroy
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
59
74
|
ちなみにcreate(:comment)自体は通ります
|
3
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,16 +14,17 @@
|
|
14
14
|
### comments_controller_spec.rb
|
15
15
|
|
16
16
|
```
|
17
|
-
|
17
|
+
describe "#create" do
|
18
|
-
|
18
|
+
let(:params) { { comment: {build(:comment).attributes} } }
|
19
|
-
|
19
|
+
subject {
|
20
|
-
|
20
|
+
post :create,
|
21
|
-
|
21
|
+
params: params
|
22
|
-
|
22
|
+
}
|
23
|
+
|
23
|
-
|
24
|
+
it "データベースに新しいコメントが登録されること" do
|
24
|
-
|
25
|
+
expect{ subject }.to change(Comment, :count).by(1)
|
25
|
-
|
26
|
+
end
|
26
|
-
|
27
|
+
end
|
27
28
|
```
|
28
29
|
|
29
30
|
### comments_controller.rb
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -47,7 +47,7 @@
|
|
47
47
|
factory :comment do
|
48
48
|
profile_id "1"
|
49
49
|
post_id "1"
|
50
|
-
text
|
50
|
+
text "hogehoge"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
it "データベースに新しいコメントが登録されること" do
|
24
24
|
expect{ subject }.to change(Comment, :count).by(1)
|
25
25
|
end
|
26
|
+
end
|
26
27
|
```
|
27
28
|
|
28
29
|
### comments_controller.rb
|