Skip to content

Commit

Permalink
AddToCollectionActor adds collections on create
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Apr 1, 2016
1 parent 4be86d5 commit 42a32c6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module CurationConcerns
class AddToCollectionActor < AbstractActor
# def create(attributes)
# attributes.delete(:collection_ids)
# next_actor.create(attributes)
# end
def create(attributes)
collection_ids = attributes.delete(:collection_ids)
next_actor.create(attributes) && add_to_collections(collection_ids)
end

def update(attributes)
collection_ids = attributes.delete(:collection_ids)
Expand Down
39 changes: 39 additions & 0 deletions spec/actors/curation_concerns/add_to_collections_actor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'
describe CurationConcerns::AddToCollectionActor do
let(:user) { create(:user) }
let(:curation_concern) { GenericWork.new }
let(:attributes) { {} }
subject do
CurationConcerns::CurationConcern::ActorStack.new(curation_concern,
user,
[described_class,
CurationConcerns::GenericWorkActor])
end
describe 'the next actor' do
let(:root_actor) { double }
before do
allow(CurationConcerns::RootActor).to receive(:new).and_return(root_actor)
end

let(:attributes) do
{ collection_ids: ['123'], title: ['test'] }
end

it 'does not receive the collection_ids' do
expect(root_actor).to receive(:create).with(title: ['test'])
subject.create(attributes)
end
end

describe 'create' do
let(:collection) { create(:collection) }
let(:attributes) do
{ collection_ids: [collection.id], title: ['test'] }
end

it 'adds it to the collection' do
expect(subject.create(attributes)).to be true
expect(collection.reload.members).to eq [curation_concern]
end
end
end

0 comments on commit 42a32c6

Please sign in to comment.