#1469: add condition for when all forum topics are read

This commit is contained in:
r888888888
2014-03-19 13:08:26 -07:00
parent a1817bd0c3
commit 4f6a48d773
2 changed files with 16 additions and 0 deletions

View File

@@ -144,6 +144,8 @@ class ForumTopic < ActiveRecord::Base
topic = query.first
if topic
CurrentUser.user.update_attribute(:last_forum_read_at, topic.updated_at)
else
CurrentUser.user.update_attribute(:last_forum_read_at, Time.now)
end
end

View File

@@ -38,6 +38,20 @@ class ForumTopicTest < ActiveSupport::TestCase
@user.reload
assert_equal(@topics[1].updated_at.to_i, @user.last_forum_read_at.to_i)
end
context "when all topics have been read" do
setup do
@read_forum_topic_ids = ForumTopic.all.map(&:id)
@timestamp = Time.now
Time.stubs(:now).returns(@timestamp)
end
should "return the current time" do
@topic.update_last_forum_read_at(@read_forum_topic_ids)
@user.reload
assert_equal(@timestamp.to_i, @user.last_forum_read_at.to_i)
end
end
end
context "when the user's last_forum_read_at is 2 days from now" do