-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop add_as_member_of_collections_actor from removing works from othe…
…r users' collections fixes samvera-deprecated/sufia#3011
- Loading branch information
1 parent
76142e1
commit a789e14
Showing
2 changed files
with
61 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
58 changes: 58 additions & 0 deletions
58
spec/actors/curation_concerns/add_as_member_of_collections_actor_spec.rb
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,58 @@ | ||
require 'spec_helper' | ||
describe CurationConcerns::Actors::AddAsMemberOfCollectionsActor do | ||
let(:user) { create(:user) } | ||
let(:curation_concern) { GenericWork.new } | ||
let(:attributes) { {} } | ||
let(:collection) { FactoryGirl.create(:collection, user: user, title: ['A good title']) } | ||
subject do | ||
CurationConcerns::Actors::ActorStack.new(curation_concern, | ||
user, | ||
[described_class, | ||
CurationConcerns::Actors::GenericWorkActor]) | ||
end | ||
describe 'the next actor' do | ||
let(:root_actor) { double } | ||
before do | ||
allow(CurationConcerns::Actors::RootActor).to receive(:new).and_return(root_actor) | ||
end | ||
|
||
let(:attributes) do | ||
{ member_of_collection_ids: [collection.id], title: ['test'] } | ||
end | ||
|
||
it 'does not receive the member_of_collection_ids' do | ||
expect(root_actor).to receive(:create).with(title: ['test']) | ||
subject.create(attributes) | ||
end | ||
end | ||
|
||
describe 'create' do | ||
let(:attributes) do | ||
{ member_of_collection_ids: [collection.id], title: ['test'] } | ||
end | ||
|
||
it 'adds it to the collection' do | ||
expect(subject.create(attributes)).to be true | ||
expect(curation_concern.member_of_collections).to eq [collection] | ||
end | ||
|
||
describe "when work is in user's own collection" do | ||
it "removes the work from that collection" do | ||
subject.create(attributes) | ||
expect(subject.create(member_of_collection_ids: [])).to be true | ||
expect(curation_concern.member_of_collections).to eq [] | ||
end | ||
end | ||
|
||
describe "when work is in another user's collection" do | ||
let(:other_user) { create(:user) } | ||
let(:collection) { FactoryGirl.create(:collection, user: other_user, title: ['A good title']) } | ||
|
||
it "doesn't remove the work from that collection" do | ||
subject.create(attributes) | ||
expect(subject.create(member_of_collection_ids: [])).to be true | ||
expect(curation_concern.member_of_collections).to eq [collection] | ||
end | ||
end | ||
end | ||
end |