2014-03-11 16:28:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
require_dependency 'backup'
|
|
|
|
|
|
|
|
describe Backup do
|
|
|
|
|
|
|
|
let(:b1) { Backup.new('backup1') }
|
|
|
|
let(:b2) { Backup.new('backup2') }
|
|
|
|
let(:b3) { Backup.new('backup3') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Backup.stubs(:all).returns([b1, b2, b3])
|
|
|
|
end
|
|
|
|
|
|
|
|
context '#remove_old' do
|
|
|
|
it "does nothing if there aren't more backups than the setting" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.maximum_backups = 3
|
2014-03-11 16:28:12 -05:00
|
|
|
Backup.any_instance.expects(:remove).never
|
|
|
|
Backup.remove_old
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls remove on the backups over our limit" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.maximum_backups = 1
|
2014-03-11 16:28:12 -05:00
|
|
|
b1.expects(:remove).never
|
|
|
|
b2.expects(:remove).once
|
|
|
|
b3.expects(:remove).once
|
|
|
|
Backup.remove_old
|
|
|
|
end
|
|
|
|
end
|
2014-03-12 15:23:47 -05:00
|
|
|
|
|
|
|
context ".after_create_hook" do
|
|
|
|
it "calls upload_to_s3 if the SiteSetting is true" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.enable_s3_backups = true
|
2014-03-12 15:23:47 -05:00
|
|
|
b1.expects(:upload_to_s3).once
|
|
|
|
b1.after_create_hook
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls upload_to_s3 if the SiteSetting is false" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.enable_s3_backups = false
|
2014-03-12 15:23:47 -05:00
|
|
|
b1.expects(:upload_to_s3).never
|
|
|
|
b1.after_create_hook
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context ".after_remove_hook" do
|
|
|
|
it "calls remove_from_s3 if the SiteSetting is true" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.enable_s3_backups = true
|
2014-03-12 15:23:47 -05:00
|
|
|
b1.expects(:remove_from_s3).once
|
|
|
|
b1.after_remove_hook
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls remove_from_s3 if the SiteSetting is false" do
|
2015-06-03 05:14:00 -05:00
|
|
|
SiteSetting.enable_s3_backups = false
|
2014-03-12 15:23:47 -05:00
|
|
|
b1.expects(:remove_from_s3).never
|
|
|
|
b1.after_remove_hook
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-11 16:28:12 -05:00
|
|
|
end
|