Skip to content

Commit

Permalink
Stop add_as_member_of_collections_actor from removing works from othe…
Browse files Browse the repository at this point in the history
…r users' collections fixes samvera-deprecated/sufia#3011
  • Loading branch information
hackartisan committed Jan 13, 2017
1 parent 76142e1 commit a789e14
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def update(attributes)
# Maps from collection ids to collection objects
def add_to_collections(collection_ids)
return true unless collection_ids
# grab/save collections this user has no edit access to
other_collections = curation_concern.member_of_collections.select { |coll| !coll.edit_users.include?(user.email) }
curation_concern.member_of_collections = collection_ids.map { |id| ::Collection.find(id) }
curation_concern.member_of_collections.concat other_collections
end
end
end
Expand Down
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

0 comments on commit a789e14

Please sign in to comment.