mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Allow category to auto-close topics in X hours instead of days. FIX: the system message that says a topic was automatically closed was only counting in days.
This commit is contained in:
@@ -51,7 +51,7 @@ describe CategoriesController do
|
||||
|
||||
xhr :post, :create, name: "hello", color: "ff0", text_color: "fff",
|
||||
hotness: 2,
|
||||
auto_close_days: 3,
|
||||
auto_close_hours: 72,
|
||||
permissions: {
|
||||
"everyone" => readonly,
|
||||
"staff" => create_post
|
||||
@@ -65,7 +65,7 @@ describe CategoriesController do
|
||||
category.name.should == "hello"
|
||||
category.color.should == "ff0"
|
||||
category.hotness.should == 2
|
||||
category.auto_close_days.should == 3
|
||||
category.auto_close_hours.should == 72
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -152,7 +152,7 @@ describe CategoriesController do
|
||||
|
||||
xhr :put, :update, id: @category.id, name: "hello", color: "ff0", text_color: "fff",
|
||||
hotness: 2,
|
||||
auto_close_days: 3,
|
||||
auto_close_hours: 72,
|
||||
permissions: {
|
||||
"everyone" => readonly,
|
||||
"staff" => create_post
|
||||
@@ -166,7 +166,7 @@ describe CategoriesController do
|
||||
@category.name.should == "hello"
|
||||
@category.color.should == "ff0"
|
||||
@category.hotness.should == 2
|
||||
@category.auto_close_days.should == 3
|
||||
@category.auto_close_hours.should == 72
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ describe Topic do
|
||||
end
|
||||
|
||||
context 'category without default auto-close' do
|
||||
Given(:category) { Fabricate(:category, auto_close_days: nil) }
|
||||
Given(:category) { Fabricate(:category, auto_close_hours: nil) }
|
||||
Then { topic.auto_close_at.should be_nil }
|
||||
And { scheduled_jobs_for(:close_topic).should be_empty }
|
||||
end
|
||||
@@ -50,8 +50,8 @@ describe Topic do
|
||||
end
|
||||
|
||||
context 'category has a default auto-close' do
|
||||
Given(:category) { Fabricate(:category, auto_close_days: 2.0) }
|
||||
Then { topic.auto_close_at.should == 2.days.from_now }
|
||||
Given(:category) { Fabricate(:category, auto_close_hours: 2.0) }
|
||||
Then { topic.auto_close_at.should be_within_one_second_of(2.hours.from_now) }
|
||||
And { topic.auto_close_started_at.should == Time.zone.now }
|
||||
And { scheduled_jobs_for(:close_topic, {topic_id: topic.id}).should have(1).job }
|
||||
And { scheduled_jobs_for(:close_topic, {topic_id: category.topic.id}).should be_empty }
|
||||
@@ -76,8 +76,8 @@ describe Topic do
|
||||
Then { scheduled_jobs_for(:close_topic, {topic_id: regular_user_topic.id, user_id: system_user.id}).should have(1).job }
|
||||
end
|
||||
|
||||
context 'auto_close_days of topic was set to 0' do
|
||||
Given(:dont_close_topic) { Fabricate(:topic, auto_close_days: 0, category: category) }
|
||||
context 'auto_close_hours of topic was set to 0' do
|
||||
Given(:dont_close_topic) { Fabricate(:topic, auto_close_hours: 0, category: category) }
|
||||
Then { scheduled_jobs_for(:close_topic).should be_empty }
|
||||
end
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ describe Category do
|
||||
end
|
||||
|
||||
it "should not set its description topic to auto-close" do
|
||||
category = Fabricate(:category, name: 'Closing Topics', auto_close_days: 1)
|
||||
category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1)
|
||||
category.topic.auto_close_at.should be_nil
|
||||
end
|
||||
|
||||
|
||||
@@ -554,7 +554,7 @@ describe Topic do
|
||||
it 'puts the autoclose duration in the moderator post' do
|
||||
@topic.created_at = 7.days.ago
|
||||
Timecop.freeze(2.days.ago) do
|
||||
@topic.set_auto_close(2)
|
||||
@topic.set_auto_close(48)
|
||||
end
|
||||
@topic.update_status(status, true, @user)
|
||||
expect(@topic.posts.last.raw).to include "closed after 2 days"
|
||||
@@ -932,8 +932,8 @@ describe Topic do
|
||||
context 'auto_close_at is set' do
|
||||
it 'queues a job to close the topic' do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
Jobs.expects(:enqueue_at).with(7.days.from_now, :close_topic, all_of( has_key(:topic_id), has_key(:user_id) ))
|
||||
Fabricate(:topic, auto_close_days: 7, user: Fabricate(:admin))
|
||||
Jobs.expects(:enqueue_at).with(7.hours.from_now, :close_topic, all_of( has_key(:topic_id), has_key(:user_id) ))
|
||||
Fabricate(:topic, auto_close_hours: 7, user: Fabricate(:admin))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -942,7 +942,7 @@ describe Topic do
|
||||
Jobs.expects(:enqueue_at).with do |datetime, job_name, job_args|
|
||||
job_args[:user_id] == topic_creator.id
|
||||
end
|
||||
Fabricate(:topic, auto_close_days: 7, user: topic_creator)
|
||||
Fabricate(:topic, auto_close_hours: 7, user: topic_creator)
|
||||
end
|
||||
|
||||
it 'when auto_close_user_id is set, it will use it as the topic closer' do
|
||||
@@ -951,19 +951,19 @@ describe Topic do
|
||||
Jobs.expects(:enqueue_at).with do |datetime, job_name, job_args|
|
||||
job_args[:user_id] == topic_closer.id
|
||||
end
|
||||
Fabricate(:topic, auto_close_days: 7, auto_close_user: topic_closer, user: topic_creator)
|
||||
Fabricate(:topic, auto_close_hours: 7, auto_close_user: topic_closer, user: topic_creator)
|
||||
end
|
||||
|
||||
it "ignores the category's default auto-close" do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
Jobs.expects(:enqueue_at).with(7.days.from_now, :close_topic, all_of( has_key(:topic_id), has_key(:user_id) ))
|
||||
Fabricate(:topic, auto_close_days: 7, user: Fabricate(:admin), category_id: Fabricate(:category, auto_close_days: 2).id)
|
||||
Jobs.expects(:enqueue_at).with(7.hours.from_now, :close_topic, all_of( has_key(:topic_id), has_key(:user_id) ))
|
||||
Fabricate(:topic, auto_close_hours: 7, user: Fabricate(:admin), category_id: Fabricate(:category, auto_close_hours: 2).id)
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets the time when auto_close timer starts' do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
topic = Fabricate(:topic, auto_close_days: 7, user: Fabricate(:admin))
|
||||
topic = Fabricate(:topic, auto_close_hours: 7, user: Fabricate(:admin))
|
||||
expect(topic.auto_close_started_at).to eq(Time.zone.now)
|
||||
end
|
||||
end
|
||||
@@ -1048,7 +1048,7 @@ describe Topic do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
mod = Fabricate(:moderator)
|
||||
# NOTE, only moderators can auto-close, if missing system user is used
|
||||
topic = Fabricate(:topic, category: Fabricate(:category, auto_close_days: 14), user: mod)
|
||||
topic = Fabricate(:topic, category: Fabricate(:category, auto_close_hours: 14), user: mod)
|
||||
Jobs.expects(:enqueue_at).with(12.hours.from_now, :close_topic, has_entries(topic_id: topic.id, user_id: topic.user_id))
|
||||
topic.auto_close_at = 12.hours.from_now
|
||||
topic.save
|
||||
@@ -1067,25 +1067,25 @@ describe Topic do
|
||||
end
|
||||
end
|
||||
|
||||
describe "auto_close_days=" do
|
||||
describe "auto_close_hours=" do
|
||||
subject(:topic) { Fabricate.build(:topic) }
|
||||
|
||||
it 'can take a number' do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
topic.auto_close_days = 2
|
||||
topic.auto_close_at.should be_within_one_second_of(2.days.from_now)
|
||||
topic.auto_close_hours = 2
|
||||
topic.auto_close_at.should be_within_one_second_of(2.hours.from_now)
|
||||
end
|
||||
end
|
||||
|
||||
it 'can take nil' do
|
||||
topic.auto_close_days = nil
|
||||
topic.auto_close_hours = nil
|
||||
topic.auto_close_at.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'set_auto_close' do
|
||||
let(:topic) { Fabricate.build(:topic) }
|
||||
let(:closing_topic) { Fabricate.build(:topic, auto_close_days: 5) }
|
||||
let(:closing_topic) { Fabricate.build(:topic, auto_close_hours: 5) }
|
||||
let(:admin) { Fabricate.build(:user, id: 123) }
|
||||
|
||||
before { Discourse.stubs(:system_user).returns(admin) }
|
||||
|
||||
Reference in New Issue
Block a user