From 9428ad779f9b58dca30d0096c69822c7a471aefb Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 23 Sep 2014 09:25:53 +1000 Subject: [PATCH] FIX: send content length with backups --- app/controllers/admin/backups_controller.rb | 1 + spec/controllers/admin/backups_controller_spec.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb index 9c8aa132b09..fac8c8f836f 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 dd63616911b..78cf8f1c4fa 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