FEATURE: auto-close topics based on last post

This commit is contained in:
Régis Hanol
2014-10-10 18:21:44 +02:00
parent ac72b0bcf6
commit 5754e8dd0f
28 changed files with 242 additions and 146 deletions

View File

@ -865,12 +865,14 @@ describe TopicsController do
describe 'autoclose' do
it 'needs you to be logged in' do
lambda { xhr :put, :autoclose, topic_id: 99, auto_close_time: '24'}.should raise_error(Discourse::NotLoggedIn)
-> {
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false
}.should raise_error(Discourse::NotLoggedIn)
end
it 'needs you to be an admin or mod' do
user = log_in
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24'
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false
response.should be_forbidden
end
@ -880,16 +882,17 @@ describe TopicsController do
@topic = Fabricate(:topic, user: @admin)
end
it "can set a topic's auto close time" do
it "can set a topic's auto close time and 'based on last post' property" do
Topic.any_instance.expects(:set_auto_close).with("24", @admin)
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: '24'
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: '24', auto_close_based_on_last_post: true
json = ::JSON.parse(response.body)
json.should have_key('auto_close_at')
json.should have_key('auto_close_hours')
end
it "can remove a topic's auto close time" do
Topic.any_instance.expects(:set_auto_close).with(nil, anything)
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: nil
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: nil, auto_close_based_on_last_post: false
end
end