-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6524 from pulibrary/6509-delete-file-sets
Add service and task to delete all file sets from a resource
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
class FileSetService | ||
def self.delete_all_from(resource_id) | ||
new.delete_all_from(resource_id: resource_id) | ||
end | ||
|
||
def delete_all_from(resource_id:) | ||
resource = query_service.find_by(id: resource_id) | ||
change_set_persister.buffer_into_index do |buffered_change_set_persister| | ||
Wayfinder.for(resource).file_sets.each do |file_set| | ||
buffered_change_set_persister.delete(change_set: ChangeSet.for(file_set)) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def change_set_persister | ||
@change_set_persister ||= ChangeSetPersister.default | ||
end | ||
|
||
def query_service | ||
change_set_persister.query_service | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
namespace :figgy do | ||
namespace :file_sets do | ||
desc "Delete all FileSets from a resource" | ||
task delete: :environment do | ||
resource_id = ENV["ID"] | ||
abort "usage: ID=id rake figgy:file_sets:delete" unless resource_id | ||
|
||
FileSetService.delete_all_from(resource_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe FileSetService do | ||
describe ".delete_all_from" do | ||
it "deletes all member file sets from a resource but no other member types" do | ||
resource = FactoryBot.create_for_repository(:scanned_map_with_raster_child, state: "pending") | ||
wayfinder = Wayfinder.for(resource) | ||
file_sets = wayfinder.file_sets | ||
raster_children = wayfinder.raster_resources | ||
expect(file_sets.count).to eq 1 | ||
expect(raster_children.count).to eq 1 | ||
|
||
described_class.delete_all_from(resource.id.to_s) | ||
reloaded = ChangeSetPersister.default.query_service.find_by(id: resource.id.to_s) | ||
wayfinder = Wayfinder.for(reloaded) | ||
file_sets = wayfinder.file_sets | ||
raster_children = wayfinder.raster_resources | ||
expect(file_sets.count).to eq 0 | ||
expect(raster_children.count).to eq 1 | ||
end | ||
end | ||
end |