forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/stable' into pkgr
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Jobs::DownloadBackupEmail do | ||
let(:user) { Fabricate(:admin) } | ||
|
||
it "should work" do | ||
described_class.new.execute( | ||
user_id: user.id, | ||
backup_file_path: "http://some.example.test/" | ||
) | ||
|
||
email = ActionMailer::Base.deliveries.last | ||
|
||
expect(email.subject).to eq(I18n.t('download_backup_mailer.subject_template', | ||
email_prefix: SiteSetting.title | ||
)) | ||
|
||
expect(email.body.raw_source).to eq(I18n.t('download_backup_mailer.text_body_template', | ||
backup_file_path: "http://some.example.test/?token=#{EmailBackupToken.get(user.id)}" | ||
)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Admin::BackupsController do | ||
let(:admin) { Fabricate(:admin) } | ||
|
||
before do | ||
sign_in(admin) | ||
end | ||
|
||
describe '#rollback' do | ||
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 | ||
expect { get "/admin/backups/rollback.json" } | ||
.to raise_error(ActionController::RoutingError) | ||
end | ||
end | ||
|
||
describe '#cancel' do | ||
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 | ||
expect { get "/admin/backups/cancel.json" } | ||
.to raise_error(ActionController::RoutingError) | ||
end | ||
end | ||
|
||
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 | ||
end |