Skip to content

Commit 13bbd82

Browse files
committed
Add tests for following new threads on a post
1 parent a385b7f commit 13bbd82

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

test/comments_test_helpers.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def try_unfollow_thread(thread)
7171
post :thread_unrestrict, params: { id: thread.id, type: 'follow' }
7272
end
7373

74+
# Attempts to follow new threads on a given post
75+
# @param post [Post] post to follow
76+
def try_post_follow(test_post)
77+
post :post_follow, params: { post_id: test_post.id }
78+
end
79+
80+
# Attempts to unfollow new threads on a given post
81+
# @param post [Post] post to unfollow
82+
def try_post_unfollow(test_post)
83+
post :post_follow, params: { post_id: test_post.id }
84+
end
85+
7486
# Attempts to lock a given comment thread
7587
# @param thread [CommentThread] thread to lock
7688
# @param duration [Integer] lock duration, in days
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'test_helper'
2+
require 'comments_test_helpers'
3+
4+
class CommentsControllerTest < ActionController::TestCase
5+
test 'post follower can unfollow post' do
6+
user = users(:standard_user)
7+
sign_in user
8+
question = posts(:question_one)
9+
10+
# Assert user follows post
11+
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
12+
13+
try_post_unfollow(question)
14+
assert_response(:found)
15+
16+
# Assert user does not follow post
17+
assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
18+
end
19+
20+
test 'non-follower can follow post' do
21+
user = users(:basic_user)
22+
sign_in user
23+
question = posts(:question_one)
24+
25+
# Assert user does not follow post
26+
assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
27+
28+
try_post_follow(question)
29+
assert_response(:found)
30+
31+
# Assert user follows post
32+
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
33+
end
34+
end

test/fixtures/thread_followers.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ deleter_normal:
55
standard_author_normal:
66
user: standard_user
77
comment_thread: normal
8+
9+
standard_author_question_one:
10+
user: standard_user
11+
post: question_one

0 commit comments

Comments
 (0)