diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb index 9c8aa132b..fac8c8f83 100644 --- a/app/controllers/admin/backups_controller.rb +++ b/app/controllers/admin/backups_controller.rb @@ -46,6 +46,7 @@ class Admin::BackupsController < Admin::AdminController def show filename = params.fetch(:id) if backup = Backup[filename] + headers['Content-Length'] = File.size(backup.path) send_file backup.path else render nothing: true, status: 404 diff --git a/spec/controllers/admin/backups_controller_spec.rb b/spec/controllers/admin/backups_controller_spec.rb index dd6361691..78cf8f1c4 100644 --- a/spec/controllers/admin/backups_controller_spec.rb +++ b/spec/controllers/admin/backups_controller_spec.rb @@ -101,13 +101,16 @@ describe Admin::BackupsController do describe ".show" do it "uses send_file to transmit the backup" do - controller.stubs(:render) # we need this since we're stubing send_file + File.open(Backup.base_directory << "/" << backup_filename, "w") do |f| + f.write("hello") + end - backup = Backup.new("backup42") - Backup.expects(:[]).with(backup_filename).returns(backup) - subject.expects(:send_file).with(backup.path) + Backup.create_from_filename(backup_filename) get :show, id: backup_filename + + response.headers['Content-Length'].should == 5 + response.headers['Content-Disposition'].should =~ /attachment; filename/ end it "returns 404 when the backup does not exist" do