mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: move a topic from PM to regular topic or vice versa
This commit is contained in:
@ -1235,4 +1235,63 @@ describe TopicsController do
|
||||
expect(response.headers['X-Robots-Tag']).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "convert_topic" do
|
||||
it 'needs you to be logged in' do
|
||||
expect { xhr :put, :convert_topic, id: 111, type: "private" }.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
describe 'converting public topic to private message' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
log_in
|
||||
xhr :put, :convert_topic, id: topic.id, type: "private"
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
context "success" do
|
||||
before do
|
||||
admin = log_in(:admin)
|
||||
Topic.any_instance.expects(:convert_to_private_message).with(admin).returns(topic)
|
||||
xhr :put, :convert_topic, id: topic.id, type: "private"
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
expect(response).to be_success
|
||||
result = ::JSON.parse(response.body)
|
||||
expect(result['success']).to eq(true)
|
||||
expect(result['url']).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'converting private message to public topic' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
log_in
|
||||
xhr :put, :convert_topic, id: topic.id, type: "public"
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
context "success" do
|
||||
before do
|
||||
admin = log_in(:admin)
|
||||
Topic.any_instance.expects(:convert_to_public_topic).with(admin).returns(topic)
|
||||
xhr :put, :convert_topic, id: topic.id, type: "public"
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
expect(response).to be_success
|
||||
result = ::JSON.parse(response.body)
|
||||
expect(result['success']).to eq(true)
|
||||
expect(result['url']).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user