2013-07-04 09:47:12 +08:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require_dependency 'post_destroyer'
|
|
|
|
|
|
|
|
describe TopicStatusUpdate do
|
2014-10-30 04:26:32 +08:00
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
2013-07-04 09:47:12 +08:00
|
|
|
it "avoids notifying on automatically closed topics" do
|
|
|
|
# TODO: TopicStatusUpdate should supress message bus updates from the users it "pretends to read"
|
|
|
|
post = PostCreator.create(user,
|
|
|
|
raw: "this is a test post 123 this is a test post",
|
|
|
|
title: "hello world title",
|
|
|
|
)
|
2014-10-30 04:26:32 +08:00
|
|
|
# TODO needed so counts sync up, PostCreator really should not give back out-of-date Topic
|
2013-07-04 09:47:12 +08:00
|
|
|
post.topic.reload
|
|
|
|
|
|
|
|
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(post.topic.posts.count).to eq(2)
|
2013-07-04 09:47:12 +08:00
|
|
|
|
2014-05-06 21:41:59 +08:00
|
|
|
tu = TopicUser.find_by(user_id: user.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(tu.last_read_post_number).to eq(2)
|
2013-07-04 09:47:12 +08:00
|
|
|
end
|
2014-10-30 04:26:32 +08:00
|
|
|
|
|
|
|
it "adds an autoclosed message" do
|
|
|
|
topic = create_topic
|
|
|
|
|
|
|
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
2014-10-30 04:26:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "adds an autoclosed message based on last post" do
|
|
|
|
topic = create_topic
|
|
|
|
topic.auto_close_based_on_last_post = true
|
|
|
|
|
|
|
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0))
|
2014-10-30 04:26:32 +08:00
|
|
|
end
|
|
|
|
|
2013-07-04 09:47:12 +08:00
|
|
|
end
|