FEATURE: move a topic from PM to regular topic or vice versa

This commit is contained in:
Arpit Jalan
2016-05-01 17:18:43 +05:30
parent e2928f78d2
commit acfb540952
13 changed files with 280 additions and 3 deletions

View File

@ -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