forum: fix topics being incorrectly marked as unread (again).

Second attempt at 71690cacc. Fix topics on page 2+ being still marked as
unread after the user has marked all topics as read.
This commit is contained in:
evazion
2020-01-22 18:33:03 -06:00
parent 22cb0ea322
commit cc96f30e47
6 changed files with 69 additions and 90 deletions

View File

@@ -15,80 +15,6 @@ class ForumTopicTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "read_by_user" do
context "with a populated @user.last_forum_read_at" do
setup do
@user.update_attribute(:last_forum_read_at, Time.now)
end
context "and no visits for a topic" do
setup do
@topic.update_column(:updated_at, 1.day.from_now)
end
should "return nothing" do
assert_equal([], ForumTopic.read_by_user(@user).map(&:id))
end
end
context "and a visit for a topic" do
setup do
@topic.update_column(:updated_at, 1.day.from_now)
end
context "that predates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 16.hours.from_now)
end
should "return nothing" do
assert_equal([], ForumTopic.read_by_user(@user).map(&:id))
end
end
context "that postdates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 2.days.from_now)
end
should "return the topic" do
assert_equal([@topic.id], ForumTopic.read_by_user(@user).map(&:id))
end
end
end
end
context "with a blank @user.last_forum_read_at" do
context "and no visits" do
should "return nothing" do
assert_equal([], ForumTopic.read_by_user(@user).map(&:id))
end
end
context "and a visit" do
context "that predates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.ago)
end
should "return nothing" do
assert_equal([], ForumTopic.read_by_user(@user).map(&:id))
end
end
context "that postdates the topic" do
setup do
FactoryBot.create(:forum_topic_visit, user: @user, forum_topic: @topic, last_read_at: 1.day.from_now)
end
should "return nothing" do
assert_equal([], ForumTopic.read_by_user(@user).map(&:id))
end
end
end
end
end
context "#mark_as_read!" do
context "without a previous visit" do
should "create a new visit" do