|
| 1 | +require 'test_helper' |
| 2 | +require 'comments_test_helpers' |
| 3 | + |
| 4 | +class CommentsControllerTest < ActionController::TestCase |
| 5 | + include Devise::Test::ControllerHelpers |
| 6 | + include CommentsControllerTestHelpers |
| 7 | + |
| 8 | + test 'post follower can unfollow post' do |
| 9 | + user = users(:standard_user) |
| 10 | + sign_in user |
| 11 | + question = posts(:question_one) |
| 12 | + |
| 13 | + # Assert user follows post |
| 14 | + assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count |
| 15 | + |
| 16 | + try_post_unfollow(question) |
| 17 | + assert_response(:found) |
| 18 | + |
| 19 | + # Assert user does not follow post |
| 20 | + assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count |
| 21 | + end |
| 22 | + |
| 23 | + test 'non-follower can follow post' do |
| 24 | + user = users(:basic_user) |
| 25 | + sign_in user |
| 26 | + question = posts(:question_one) |
| 27 | + |
| 28 | + # Assert user does not follow post |
| 29 | + assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count |
| 30 | + |
| 31 | + try_post_follow(question) |
| 32 | + assert_response(:found) |
| 33 | + |
| 34 | + # Assert user follows post |
| 35 | + assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count |
| 36 | + end |
| 37 | +end |
0 commit comments