質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
it "いいねに成功する" do
|
66
66
|
|
67
|
-
expect { post :create, format: :js, params: { post_id: post1.id,
|
67
|
+
expect { post :create, format: :js, params: { post_id: post1.id, id: like.id } }.to change(Like, :count).by(1)
|
68
68
|
|
69
69
|
end
|
70
70
|
|
1
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,15 +34,11 @@
|
|
34
34
|
|
35
35
|
RSpec.describe LikesController, type: :controller do
|
36
36
|
|
37
|
-
|
38
|
-
|
39
37
|
let!(:user) { create(:user) }
|
40
38
|
|
41
39
|
let!(:post1) { create(:post, user: user) }
|
42
40
|
|
43
41
|
let!(:like) { create(:like, user_id: user.id, post_id: post1.id) }
|
44
|
-
|
45
|
-
|
46
42
|
|
47
43
|
|
48
44
|
|
@@ -56,25 +52,57 @@
|
|
56
52
|
|
57
53
|
|
58
54
|
|
59
|
-
|
55
|
+
it "Ajexが反応する" do
|
60
56
|
|
61
|
-
|
57
|
+
post :create, format: :js, params: { post_id: post1.id, id: like.id }
|
62
58
|
|
63
|
-
|
59
|
+
expect(response.content_type).to eq 'text/javascript'
|
64
60
|
|
65
|
-
|
61
|
+
end
|
66
62
|
|
67
63
|
|
68
64
|
|
69
65
|
it "いいねに成功する" do
|
70
66
|
|
71
|
-
expect { post :create, format: :js, params: { post_id: post1.id, user_id: user.id } }.to change(Like, :count).by(1)
|
67
|
+
expect { post :create, format: :js, params: { post_id: post1.id, user_id: user.id, id: like.id } }.to change(Like, :count).by(1)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
describe "#destroy" do
|
76
|
+
|
77
|
+
before do
|
78
|
+
|
79
|
+
sign_in user
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
it "Ajexが反応する" do
|
86
|
+
|
87
|
+
delete :destroy, format: :js, params: { post_id: post1.id, user_id: user.id, id: like.id }
|
88
|
+
|
89
|
+
expect(response.content_type).to eq 'text/javascript'
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
it "いいねの削除に成功する" do
|
96
|
+
|
97
|
+
expect { delete :destroy, format: :js, params: { post_id: post1.id, user_id: user.id, id: like.id } }.to change(Like, :count).by(-1)
|
72
98
|
|
73
99
|
end
|
74
100
|
|
75
101
|
end
|
76
102
|
|
77
103
|
end
|
104
|
+
|
105
|
+
|
78
106
|
|
79
107
|
|
80
108
|
|