mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
Fix all the errors to get our tests green on Rails 5.1.
This commit is contained in:
@ -26,7 +26,7 @@ describe Admin::BackupsController do
|
||||
BackupRestore.expects(:logs).returns([])
|
||||
subject.expects(:store_preloaded).with("logs", "[]")
|
||||
|
||||
xhr :get, :index, format: :html
|
||||
get :index, format: :html, xhr: true
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
@ -38,7 +38,7 @@ describe Admin::BackupsController do
|
||||
it "returns a list of all the backups" do
|
||||
Backup.expects(:all).returns([Backup.new("backup1"), Backup.new("backup2")])
|
||||
|
||||
xhr :get, :index, format: :json
|
||||
get :index, format: :json, xhr: true
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
@ -56,7 +56,7 @@ describe Admin::BackupsController do
|
||||
it "returns the current backups status" do
|
||||
BackupRestore.expects(:operations_status)
|
||||
|
||||
xhr :get, :status
|
||||
get :status, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
@ -68,7 +68,9 @@ describe Admin::BackupsController do
|
||||
it "starts a backup" do
|
||||
BackupRestore.expects(:backup!).with(@admin.id, publish_to_message_bus: true, with_uploads: false, client_id: "foo")
|
||||
|
||||
xhr :post, :create, with_uploads: false, client_id: "foo"
|
||||
post :create, params: {
|
||||
with_uploads: false, client_id: "foo"
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
@ -87,7 +89,7 @@ describe Admin::BackupsController do
|
||||
|
||||
StaffActionLogger.any_instance.expects(:log_backup_download).once
|
||||
|
||||
get :show, id: backup_filename, token: token
|
||||
get :show, params: { id: backup_filename, token: token }, format: :json
|
||||
|
||||
expect(response.headers['Content-Length']).to eq("5")
|
||||
expect(response.headers['Content-Disposition']).to match(/attachment; filename/)
|
||||
@ -104,7 +106,7 @@ describe Admin::BackupsController do
|
||||
|
||||
Backup.create_from_filename(backup_filename)
|
||||
|
||||
get :show, id: backup_filename, token: "bad_value"
|
||||
get :show, params: { id: backup_filename, token: "bad_value" }, xhr: true
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
ensure
|
||||
@ -116,7 +118,7 @@ describe Admin::BackupsController do
|
||||
token = EmailBackupToken.set(@admin.id)
|
||||
Backup.expects(:[]).returns(nil)
|
||||
|
||||
get :show, id: backup_filename, token: token
|
||||
get :show, params: { id: backup_filename, token: token }, format: :json
|
||||
|
||||
EmailBackupToken.del(@admin.id)
|
||||
|
||||
@ -133,13 +135,13 @@ describe Admin::BackupsController do
|
||||
Backup.expects(:[]).with(backup_filename).returns(b)
|
||||
Jobs.expects(:enqueue).with(:download_backup_email, has_entries(to_address: @admin.email))
|
||||
|
||||
xhr :put, :email, id: backup_filename
|
||||
put :email, params: { id: backup_filename }, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "returns 404 when the backup does not exist" do
|
||||
xhr :put, :email, id: backup_filename
|
||||
put :email, params: { id: backup_filename }, format: :json
|
||||
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
@ -156,7 +158,7 @@ describe Admin::BackupsController do
|
||||
|
||||
StaffActionLogger.any_instance.expects(:log_backup_destroy).with(b).once
|
||||
|
||||
xhr :delete, :destroy, id: backup_filename
|
||||
delete :destroy, params: { id: backup_filename }, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
@ -164,7 +166,7 @@ describe Admin::BackupsController do
|
||||
it "doesn't remove the backup if not found" do
|
||||
Backup.expects(:[]).with(backup_filename).returns(nil)
|
||||
b.expects(:remove).never
|
||||
xhr :delete, :destroy, id: backup_filename
|
||||
delete :destroy, params: { id: backup_filename }, format: :json
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
@ -179,7 +181,7 @@ describe Admin::BackupsController do
|
||||
BackupRestore.expects(:logs).returns([])
|
||||
subject.expects(:store_preloaded).with("logs", "[]")
|
||||
|
||||
xhr :get, :logs, format: :html
|
||||
get :logs, format: :html, xhr: true
|
||||
|
||||
expect(response).to be_success
|
||||
end
|
||||
@ -191,7 +193,7 @@ describe Admin::BackupsController do
|
||||
expect(SiteSetting.disable_emails).to eq(false)
|
||||
BackupRestore.expects(:restore!).with(@admin.id, filename: backup_filename, publish_to_message_bus: true, client_id: "foo")
|
||||
|
||||
xhr :post, :restore, id: backup_filename, client_id: "foo"
|
||||
post :restore, params: { id: backup_filename, client_id: "foo" }, format: :json
|
||||
|
||||
expect(SiteSetting.disable_emails).to eq(true)
|
||||
expect(response).to be_success
|
||||
@ -204,7 +206,7 @@ describe Admin::BackupsController do
|
||||
it "enables readonly mode" do
|
||||
Discourse.expects(:enable_readonly_mode)
|
||||
|
||||
expect { xhr :put, :readonly, enable: true }
|
||||
expect { put :readonly, params: { enable: true }, format: :json }
|
||||
.to change { UserHistory.count }.by(1)
|
||||
|
||||
expect(response).to be_success
|
||||
@ -218,7 +220,7 @@ describe Admin::BackupsController do
|
||||
it "disables readonly mode" do
|
||||
Discourse.expects(:disable_readonly_mode)
|
||||
|
||||
expect { xhr :put, :readonly, enable: false }
|
||||
expect { put :readonly, params: { enable: false }, format: :json }
|
||||
.to change { UserHistory.count }.by(1)
|
||||
|
||||
expect(response).to be_success
|
||||
@ -236,7 +238,10 @@ describe Admin::BackupsController do
|
||||
it "should raise an error" do
|
||||
['灰色.tar.gz', '; echo \'haha\'.tar.gz'].each do |invalid_filename|
|
||||
described_class.any_instance.expects(:has_enough_space_on_disk?).returns(true)
|
||||
xhr :post, :upload_backup_chunk, resumableFilename: invalid_filename, resumableTotalSize: 1
|
||||
|
||||
post :upload_backup_chunk, params: {
|
||||
resumableFilename: invalid_filename, resumableTotalSize: 1
|
||||
}
|
||||
|
||||
expect(response.status).to eq(415)
|
||||
expect(response.body).to eq(I18n.t('backup.invalid_filename'))
|
||||
@ -251,7 +256,7 @@ describe Admin::BackupsController do
|
||||
|
||||
filename = 'test_Site-0123456789.tar.gz'
|
||||
|
||||
xhr :post, :upload_backup_chunk,
|
||||
post :upload_backup_chunk, params: {
|
||||
resumableFilename: filename,
|
||||
resumableTotalSize: 1,
|
||||
resumableIdentifier: 'test',
|
||||
@ -259,6 +264,7 @@ describe Admin::BackupsController do
|
||||
resumableChunkSize: '1',
|
||||
resumableCurrentChunkSize: '1',
|
||||
file: fixture_file_upload(Tempfile.new)
|
||||
}, format: :json
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to eq("")
|
||||
|
Reference in New Issue
Block a user