FIX: send content length with backups

This commit is contained in:
Sam 2014-09-23 09:25:53 +10:00
parent 7a4082cbad
commit 9428ad779f
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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