Skip to content

Commit ffd7791

Browse files
committed
Amend code to use NewThreadFollower model instead
1 parent 17986cd commit ffd7791

5 files changed

Lines changed: 16 additions & 14 deletions

File tree

app/controllers/comments_controller.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def create_thread
5959
@comment.post.user.create_notification(notification, helpers.comment_link(@comment))
6060
end
6161

62-
ThreadFollower.where(post: @post).each do |tf|
63-
unless tf.user == current_user || tf.user == @comment.post.user
64-
tf.user.create_notification(notification, helpers.comment_link(@comment))
62+
NewThreadFollower.where(post: @post).each do |ntf|
63+
unless ntf.user == current_user || ntf.user == @comment.post.user
64+
ntf.user.create_notification(notification, helpers.comment_link(@comment))
6565
end
66-
ThreadFollower.create(user: tf.user, comment_thread: @comment_thread)
66+
ThreadFollower.create(user: ntf.user, comment_thread: @comment_thread)
6767
end
6868

6969
apply_pings(pings)
@@ -330,8 +330,8 @@ def post
330330
end
331331

332332
def post_follow
333-
if ThreadFollower.where(post: @post, user: current_user).none?
334-
ThreadFollower.create(post: @post, user: current_user)
333+
if NewThreadFollower.where(post: @post, user: current_user).none?
334+
NewThreadFollower.create(post: @post, user: current_user)
335335
end
336336

337337
respond_to do |format|
@@ -341,7 +341,7 @@ def post_follow
341341
end
342342

343343
def post_unfollow
344-
ThreadFollower.where(post: @post, user: current_user).destroy_all
344+
NewThreadFollower.where(post: @post, user: current_user).destroy_all
345345

346346
respond_to do |format|
347347
format.html { redirect_to post_path(@post) }

app/models/concerns/user_merge.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def update_thread_references(target_user)
7171
CommentThread.where(archived_by_id: id).update_all(archived_by_id: target_user.id)
7272
CommentThread.where(deleted_by_id: id).update_all(deleted_by_id: target_user.id)
7373
ThreadFollower.where(user_id: id).update_all(user_id: target_user.id)
74+
NewThreadFollower.where(user_id: id).update_all(user_id: target_user.id)
7475
end
7576

7677
def update_post_action_references(target_user)

app/models/post.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def deleted_by_owner?
243243
# @param user [User] user to check
244244
# @return [Boolean] check result
245245
def followed_by?(user)
246-
ThreadFollower.where(post: self, user: user).any?
246+
NewThreadFollower.where(post: self, user: user).any?
247247
end
248248

249249
# Is the post an imported post?

test/controllers/comments/post_follow_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class CommentsControllerTest < ActionController::TestCase
1111
question = posts(:question_one)
1212

1313
# Assert user follows post
14-
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
14+
assert_equal 1, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
1515

1616
try_post_unfollow(question)
1717
assert_response(:found)
1818

1919
# Assert user does not follow post
20-
assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
20+
assert_equal 0, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
2121
end
2222

2323
test 'non-follower can follow post' do
@@ -26,13 +26,13 @@ class CommentsControllerTest < ActionController::TestCase
2626
question = posts(:question_one)
2727

2828
# Assert user does not follow post
29-
assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
29+
assert_equal 0, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
3030

3131
try_post_follow(question)
3232
assert_response(:found)
3333

3434
# Assert user follows post
35-
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
35+
assert_equal 1, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
3636
end
3737

3838
test 'follower cannot duplicate the following of a post' do
@@ -41,12 +41,12 @@ class CommentsControllerTest < ActionController::TestCase
4141
question = posts(:question_one)
4242

4343
# Assert user follows post
44-
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
44+
assert_equal 1, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
4545

4646
try_post_follow(question)
4747
assert_response(:found)
4848

4949
# Assert user still only follows post once
50-
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
50+
assert_equal 1, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
5151
end
5252
end

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
WarningTemplate,
2121
ModWarning,
2222
ThreadFollower,
23+
NewThreadFollower,
2324
Comment,
2425
CommentThread,
2526
Reaction,

0 commit comments

Comments
 (0)