質問編集履歴

2

文字の修正

2017/06/27 09:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -172,7 +172,7 @@
172
172
 
173
173
 
174
174
 
175
- 一応加えておきます。
175
+ 念のため記載します。
176
176
 
177
177
 
178
178
 

1

補足

2017/06/27 09:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -163,3 +163,121 @@
163
163
  **個別エラーの意味というより、better_errors削除前後でのテスト仕様(?)** について
164
164
 
165
165
  もし情報をお持ちの方、ご助言頂けるとと幸いです。宜しくお願いします。
166
+
167
+
168
+
169
+
170
+
171
+ # テストのファイル内容
172
+
173
+
174
+
175
+ 一応、加えておきます。
176
+
177
+
178
+
179
+ ```
180
+
181
+
182
+
183
+ require 'test_helper'
184
+
185
+
186
+
187
+ class FollowingTest < ActionDispatch::IntegrationTest
188
+
189
+
190
+
191
+ def setup
192
+
193
+ @user = users(:michael)
194
+
195
+ @host = hosts(:google)
196
+
197
+ log_in_as(@user)
198
+
199
+ end
200
+
201
+
202
+
203
+ test "フォローリストページ" do
204
+
205
+ get following_user_mypage_path
206
+
207
+ assert_not @user.following.empty?
208
+
209
+ assert_match @user.following.count.to_s,response.body
210
+
211
+ @user.following.each do |host|
212
+
213
+ assert_select "a[href=?]",user_host_path(host)
214
+
215
+ end
216
+
217
+ end
218
+
219
+
220
+
221
+ test "フォロー" do
222
+
223
+ assert_difference '@user.following.count',1 do
224
+
225
+ post user_relationships_path, params: { followed_id: @host.id }
226
+
227
+ end
228
+
229
+ end
230
+
231
+
232
+
233
+ test "フォロー(Ajax)" do
234
+
235
+ assert_difference '@user.following.count',1 do
236
+
237
+ post user_relationships_path, params: { followed_id: @host.id }, xhr: true
238
+
239
+ end
240
+
241
+ end
242
+
243
+
244
+
245
+ test "フォロー解除" do
246
+
247
+ @user.follow(@host)
248
+
249
+ relationship = @user.active_relationships.find_by(followed_id: @host.id)
250
+
251
+ assert_difference '@user.following.count', -1 do
252
+
253
+ delete user_relationship_path(relationship)
254
+
255
+ end
256
+
257
+ end
258
+
259
+
260
+
261
+ test "フォロー解除(Ajax)" do
262
+
263
+ @user.follow(@host)
264
+
265
+ relationship = @user.active_relationships.find_by(followed_id: @host.id)
266
+
267
+ assert_difference '@user.following.count', -1 do
268
+
269
+ delete user_relationship_path(relationship),xhr:true
270
+
271
+ end
272
+
273
+ end
274
+
275
+
276
+
277
+ end
278
+
279
+
280
+
281
+
282
+
283
+ ```