mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 17:51:39 -05:00
Merge pull request #809 from Freika/fix/delete-export-file
Fix deleting export file
This commit is contained in:
commit
073b3afc71
3 changed files with 24 additions and 13 deletions
|
|
@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
### Fixed
|
||||
|
||||
- After deleting one point from the map, other points can now be deleted as well. #723 #678
|
||||
|
||||
- Fixed a bug where export file was not being deleted from the server after it was deleted. #808
|
||||
### Added
|
||||
|
||||
- `X-Dawarich-Version` header to the `GET /api/v1/health` endpoint response. #800
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ class ExportsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@export.destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
@export.destroy
|
||||
|
||||
File.delete(Rails.root.join('public', 'exports', @export.name))
|
||||
end
|
||||
|
||||
redirect_to exports_url, notice: 'Export was successfully destroyed.', status: :see_other
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,9 +76,25 @@ RSpec.describe '/exports', type: :request do
|
|||
end
|
||||
|
||||
describe 'DELETE /destroy' do
|
||||
let!(:export) { create(:export, user:, url: 'exports/export.json') }
|
||||
let!(:export) { create(:export, user:, url: 'exports/export.json', name: 'export.json') }
|
||||
let(:export_file) { Rails.root.join('public', 'exports', export.name) }
|
||||
|
||||
before { sign_in user }
|
||||
before do
|
||||
sign_in user
|
||||
|
||||
FileUtils.mkdir_p(File.dirname(export_file))
|
||||
File.write(export_file, '{"some": "data"}')
|
||||
end
|
||||
|
||||
after { FileUtils.rm_f(export_file) }
|
||||
|
||||
it 'removes the export file from disk' do
|
||||
expect(File.exist?(export_file)).to be true
|
||||
|
||||
delete export_url(export)
|
||||
|
||||
expect(File.exist?(export_file)).to be false
|
||||
end
|
||||
|
||||
it 'destroys the requested export' do
|
||||
expect { delete export_url(export) }.to change(Export, :count).by(-1)
|
||||
|
|
@ -89,14 +105,5 @@ RSpec.describe '/exports', type: :request do
|
|||
|
||||
expect(response).to redirect_to(exports_url)
|
||||
end
|
||||
|
||||
it 'remove the export file from the disk' do
|
||||
export_file = Rails.root.join('public', export.url)
|
||||
FileUtils.touch(export_file)
|
||||
|
||||
delete export_url(export)
|
||||
|
||||
expect(File.exist?(export_file)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue