演習1 で、 format.js をコメントアウトしてもGreenになってしまう。
チュートリアルのテストが十分でない。
- ユーザのフォロー数
@user.following.countは、確認できている - format.js の効果を確認するには、レスポンスのJavascriptを確認する必要がある。
- follow のテスト:
Unfollowがある,followersの値が 1 であること - unfollow のテスト:
Followがある,followersの値が 0 であること
- follow のテスト:
ついでに、Ajaxでない場合も、レスポンスのフォロー数の統計数値を評価するようにした。
変更したテストのdiffを下記に示します。
diff --git a/test/integration/following_test.rb b/test/integration/following_test.rb
index fdde034..3fb3e5d 100644
--- a/test/integration/following_test.rb
+++ b/test/integration/following_test.rb
@@ -29,12 +29,16 @@ class FollowingTest < ActionDispatch::IntegrationTest
assert_difference '@user.following.count', 1 do
post relationships_path, params: { followed_id: @other.id }
end
+ follow_redirect!
+ assert_select 'strong#followers', text: @other.followers.count.to_s
end
test "should follow a user with Ajax" do
assert_difference '@user.following.count', 1 do
post relationships_path, xhr: true, params: { followed_id: @other.id }
end
+ assert_match "Unfollow", response.body
+ assert_match /#followers.*'1'/, response.body
end
test "should unfollow a user the standarfd way" do
@@ -43,6 +47,8 @@ class FollowingTest < ActionDispatch::IntegrationTest
assert_difference '@user.following.count', -1 do
delete relationship_path(relationship)
end
+ follow_redirect!
+ assert_select 'strong#followers', text: @other.followers.count.to_s
end
test "should unfollow a user with Ajax" do
@@ -51,5 +57,7 @@ class FollowingTest < ActionDispatch::IntegrationTest
assert_difference '@user.following.count', -1 do
delete relationship_path(relationship), xhr: true
end
+ assert_match "Follow", response.body
+ assert_match /#followers.*'0'/, response.body
end
end