implementation for #1469

This reverts commit 18edc937fd.
This commit is contained in:
r888888888
2014-03-12 18:22:15 -07:00
parent a93ce87cf3
commit 7e07b874a4
6 changed files with 84 additions and 11 deletions

View File

@@ -14,6 +14,40 @@ class ForumTopicTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "#read_by?" do
context "for a topic that was never read by the user" do
should "return false" do
assert_equal(false, @topic.read_by?(@user, [[(@topic.id + 1).to_s, "1"]]))
end
end
context "for a topic that was read by the user but has been updated since then" do
should "return false" do
assert_equal(false, @topic.read_by?(@user, [["#{@topic.id}", "#{1.day.ago.to_i}"]]))
end
end
context "for a topic that was read by the user and has not been updated since" do
should "return true" do
assert_equal(true, @topic.read_by?(@user, [["#{@topic.id}", "#{1.day.from_now.to_i}"]]))
end
end
end
context "#mark_as_read" do
should "include the topic id and updated_at timestamp" do
plus_one = @topic.id + 1
result = @topic.mark_as_read([["#{plus_one}", "2"]])
assert_equal("#{plus_one} 2 #{@topic.id} #{@topic.updated_at.to_i}", result)
end
should "prune the string if it gets too long" do
array = (1..1_000).to_a.map(&:to_s).in_groups_of(2)
result = @topic.mark_as_read(array)
assert_equal("502 503", result[0..6])
end
end
context "constructed with nested attributes for its original post" do
should "create a matching forum post" do
assert_difference(["ForumTopic.count", "ForumPost.count"], 1) do