Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
🎁 delete child works if the parent work is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Nov 10, 2023
1 parent 4e68ffa commit 7854e9f
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/models/concerns/destroyable_children.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module DestroyableChildren
extend ActiveSupport::Concern

included do
before_destroy :destroy_children
end

private

def destroy_children
ordered_works.each(&:destroy)
end
end
1 change: 1 addition & 0 deletions app/models/conference_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConferenceItem < DogBiscuits::ConferenceItem
before_save :combine_dates

prepend OrderAlready.for(:creator)
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Dataset < DogBiscuits::Dataset
before_save :combine_dates

prepend OrderAlready.for(:creator)
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
2 changes: 1 addition & 1 deletion app/models/exam_paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExamPaper < DogBiscuits::ExamPaper
before_save :combine_dates

prepend OrderAlready.for(:creator)

include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/generic_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GenericWork < ActiveFedora::Base
include SlugMetadata
include AdventistMetadata
include SlugBug
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Image < ActiveFedora::Base
include DogBiscuits::Geo
include DogBiscuits::PartOf
include DogBiscuits::PlaceOfPublication
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/journal_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JournalArticle < DogBiscuits::JournalArticle
before_save :combine_dates

prepend OrderAlready.for(:creator)
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/published_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PublishedWork < DogBiscuits::PublishedWork
before_save :combine_dates

prepend OrderAlready.for(:creator)
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
1 change: 1 addition & 0 deletions app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Thesis < DogBiscuits::Thesis
before_save :combine_dates

prepend OrderAlready.for(:creator)
include DestroyableChildren
include IiifPrint.model_configuration(
pdf_split_child_model: self,
pdf_splitter_service: IiifPrint::SplitPdfs::AdventistPagesToJpgsSplitter,
Expand Down
19 changes: 19 additions & 0 deletions spec/models/concerns/destroyable_children_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe DestroyableChildren, type: :model do
describe Image do
let(:parent) { create(:image) }
let(:child1) { create(:image) }
let(:child2) { create(:image) }

before do
allow(parent).to receive(:ordered_works).and_return([child1, child2])
end

it 'destroys child works when the parent is destroyed' do
expect { parent.destroy }.to change(Image, :count).by(-3)
end
end
end

0 comments on commit 7854e9f

Please sign in to comment.