Skip to content

Commit

Permalink
enables AddToWorkActor to remove all relationships to work_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gum committed Jun 10, 2016
1 parent bf9a87a commit 9bce34d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/actors/curation_concerns/actors/add_to_work_actor.rb
Expand Up @@ -14,7 +14,7 @@ def update(attributes)
private

def add_to_works(new_work_ids)
return true unless new_work_ids.present?
return true if new_work_ids.nil?
(curation_concern.in_works_ids - new_work_ids).each do |old_id|
work = ::ActiveFedora::Base.find(old_id)
work.ordered_members.delete(curation_concern)
Expand Down
37 changes: 37 additions & 0 deletions spec/actors/curation_concerns/work_actor_spec.rb
Expand Up @@ -204,6 +204,43 @@
expect(old_parent.reload.members).to eq []
end
end
context 'without in_works_ids' do
let(:old_parent) { FactoryGirl.create(:generic_work) }
let(:attributes) do
FactoryGirl.attributes_for(:generic_work).merge(
in_works_ids: []
)
end
before do
curation_concern.apply_depositor_metadata(user.user_key)
curation_concern.save!
old_parent.ordered_members << curation_concern
old_parent.save!
end
it "removes the old parent" do
expect(subject.update(attributes)).to be true
expect(curation_concern.in_works).to eq []
expect(old_parent.reload.members).to eq []
end
end
context 'with nil in_works_ids' do
let(:parent) { FactoryGirl.create(:generic_work) }
let(:attributes) do
FactoryGirl.attributes_for(:generic_work).merge(
in_works_ids: nil
)
end
before do
curation_concern.apply_depositor_metadata(user.user_key)
curation_concern.save!
parent.ordered_members << curation_concern
parent.save!
end
it "does nothing" do
expect(subject.update(attributes)).to be true
expect(curation_concern.in_works).to eq [parent]
end
end
context 'adding to collections' do
let!(:collection1) { create(:collection, user: user) }
let!(:collection2) { create(:collection, user: user) }
Expand Down

0 comments on commit 9bce34d

Please sign in to comment.