2017-03-22 22:29:35 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
RSpec.describe Admin::BackupsController do
|
2017-03-22 22:29:35 -04:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-12-21 15:21:28 -05:00
|
|
|
describe "#index" do
|
|
|
|
it "raises an error when backups are disabled" do
|
|
|
|
SiteSetting.enable_backups = false
|
|
|
|
get "/admin/backups.json"
|
|
|
|
expect(response).not_to be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
describe '#rollback' do
|
2017-03-22 22:29:35 -04:00
|
|
|
it 'should rollback the restore' do
|
|
|
|
BackupRestore.expects(:rollback!)
|
|
|
|
|
|
|
|
post "/admin/backups/rollback.json"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not allow rollback via a GET request' do
|
2018-01-11 22:15:10 -05:00
|
|
|
get "/admin/backups/rollback.json"
|
|
|
|
expect(response.status).to eq(404)
|
2017-03-22 22:29:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
describe '#cancel' do
|
2017-03-22 22:29:35 -04:00
|
|
|
it "should cancel an backup" do
|
|
|
|
BackupRestore.expects(:cancel!)
|
|
|
|
|
|
|
|
delete "/admin/backups/cancel.json"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not allow cancel via a GET request' do
|
2018-01-11 22:15:10 -05:00
|
|
|
get "/admin/backups/cancel.json"
|
|
|
|
expect(response.status).to eq(404)
|
2017-03-22 22:29:35 -04:00
|
|
|
end
|
|
|
|
end
|
2017-12-17 22:25:22 -05:00
|
|
|
|
|
|
|
describe "#email" do
|
|
|
|
let(:backup_filename) { "test.tar.gz" }
|
|
|
|
let(:backup) { Backup.new(backup_filename) }
|
|
|
|
|
|
|
|
it "enqueues email job" do
|
|
|
|
Backup.expects(:[]).with(backup_filename).returns(backup)
|
|
|
|
|
|
|
|
Jobs.expects(:enqueue).with(:download_backup_email,
|
|
|
|
user_id: admin.id,
|
|
|
|
backup_file_path: 'http://www.example.com/admin/backups/test.tar.gz'
|
|
|
|
)
|
|
|
|
|
|
|
|
put "/admin/backups/#{backup_filename}.json"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 when the backup does not exist" do
|
|
|
|
put "/admin/backups/#{backup_filename}.json"
|
|
|
|
|
|
|
|
expect(response).to be_not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2017-03-22 22:29:35 -04:00
|
|
|
end
|