jomaxro 1607b4e107 FIX: Don't open a topic to set an auto-close timer when marking as solved.
Fixes this issue: https://meta.discourse.org/t/marking-closed-topic-solved-with-solve-topics-auto-close-hours-set-causes-topic-to-be-reopened/63593?u=jomaxro

Topics that were closed before being marked as solved would be reopened and have an auto-close timer set.  If a topic is already closed, marking as solved should not cause it to re-open.
2017-06-12 22:29:53 +02:00

45 lines
1.2 KiB
Ruby

require 'rails_helper'
RSpec.describe "Managing Posts solved status" do
let(:topic) { Fabricate(:topic) }
let(:user) { Fabricate(:trust_level_4) }
let(:p1) { Fabricate(:post, topic: topic) }
before do
SiteSetting.allow_solved_on_all_topics = true
end
describe 'accepting a post as the answer' do
before do
sign_in(user)
SiteSetting.solved_topics_auto_close_hours = 2
end
it 'can mark a post as the accepted answer correctly' do
xhr :post, "/solution/accept", id: p1.id
expect(p1.reload.custom_fields["is_accepted_answer"]).to eq("true")
expect(topic.public_topic_timer.status_type).to eq(TopicTimer.types[:close])
expect(topic.public_topic_timer.execute_at)
.to be_within(1.second).of(Time.zone.now + 2.hours)
expect(topic.public_topic_timer.based_on_last_post).to eq(true)
end
it 'does not set a timer when the topic is closed' do
topic2.update!(closed: true)
xhr :post, "/solution/accept", id: p2.id
p2.reload
topic2.reload
expect(p2.custom_fields["is_accepted_answer"]).to eq("true")
expect(topic2.public_topic_timer).to eq(nil)
expect(topic2.closed).to eq(true)
end
end
end