FIX: use PostDestroyer when deleting/recovering a topic

This commit is contained in:
Régis Hanol
2014-08-07 19:12:35 +02:00
parent ee40a95e58
commit 3ae1ebdfc3
8 changed files with 43 additions and 27 deletions

View File

@ -501,7 +501,7 @@ describe TopicsController do
end
it 'succeeds' do
Topic.any_instance.expects(:recover!)
PostDestroyer.any_instance.expects(:recover)
xhr :put, :recover, topic_id: topic.id
response.should be_success
end
@ -516,33 +516,27 @@ describe TopicsController do
end
describe 'when logged in' do
before do
@topic = Fabricate(:topic, user: log_in)
end
let(:topic) { Fabricate(:topic, user: log_in) }
describe 'without access' do
it "raises an exception when the user doesn't have permission to delete the topic" do
Guardian.any_instance.expects(:can_delete?).with(@topic).returns(false)
xhr :delete, :destroy, id: @topic.id
Guardian.any_instance.expects(:can_delete?).with(topic).returns(false)
xhr :delete, :destroy, id: topic.id
response.should be_forbidden
end
end
describe 'with permission' do
before do
Guardian.any_instance.expects(:can_delete?).with(@topic).returns(true)
Guardian.any_instance.expects(:can_delete?).with(topic).returns(true)
end
it 'succeeds' do
xhr :delete, :destroy, id: @topic.id
PostDestroyer.any_instance.expects(:destroy)
xhr :delete, :destroy, id: topic.id
response.should be_success
end
it 'deletes the topic' do
xhr :delete, :destroy, id: @topic.id
Topic.exists?(id: @topic_id).should be_false
end
end
end