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:
@@ -128,6 +128,52 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_select "a.forum-post-link", count: 0, text: @topic2.title
|
||||
end
|
||||
end
|
||||
|
||||
context "when listing topics" do
|
||||
should "always show topics as read for anonymous users" do
|
||||
get forum_topics_path
|
||||
assert_select "span.new", count: 0
|
||||
end
|
||||
|
||||
should "show topics as read after viewing them" do
|
||||
get_auth forum_topics_path, @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 3
|
||||
|
||||
get_auth forum_topic_path(@forum_topic.id), @user
|
||||
assert_response :success
|
||||
|
||||
get_auth forum_topics_path, @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 2
|
||||
end
|
||||
|
||||
should "show topics as read after marking all as read" do
|
||||
get_auth forum_topics_path, @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 3
|
||||
|
||||
post_auth mark_all_as_read_forum_topics_path, @user
|
||||
assert_response 302
|
||||
|
||||
get_auth forum_topics_path, @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 0
|
||||
end
|
||||
|
||||
should "show topics on page 2 as read after marking all as read" do
|
||||
get_auth forum_topics_path(page: 2, limit: 1), @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 1
|
||||
|
||||
post_auth mark_all_as_read_forum_topics_path, @user
|
||||
assert_response 302
|
||||
|
||||
get_auth forum_topics_path(page: 2, limit: 1), @user
|
||||
assert_response :success
|
||||
assert_select "span.new", count: 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user