Skip to content

Commit

Permalink
When attaching file_sets, set the representative & thumbnail if it is…
Browse files Browse the repository at this point in the history
…n't already set. Story curationexperts/goldenseal#134
  • Loading branch information
val99erie committed Oct 30, 2015
1 parent f7da04f commit 05c12be
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def attach_file_to_work(work, file_set, file_set_params)
copy_visibility(work, file_set)
end
work.ordered_members << file_set
set_representative(work, file_set)
set_thumbnail(work, file_set)

# Save the work so the association between the work and the file_set is persisted (head_id)
work.save
end
Expand Down Expand Up @@ -196,5 +199,15 @@ def update_visibility(attributes)
def copy_visibility(source_concern, destination_concern)
destination_concern.visibility = source_concern.visibility
end

def set_representative(work, file_set)
return unless work.representative_id.blank?
work.representative = file_set
end

def set_thumbnail(work, file_set)
return unless work.thumbnail_id.blank?
work.thumbnail = file_set
end
end
end
50 changes: 50 additions & 0 deletions spec/actors/curation_concerns/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,54 @@
expect(work_v1.members.size).to eq 3
end
end

describe "#set_representative" do
let!(:work) { build(:generic_work, representative: rep) }
let!(:file_set) { build(:file_set) }

before do
actor.send(:set_representative, work, file_set)
end

context "when the representative isn't set" do
let(:rep) { nil }

it 'sets the representative' do
expect(work.representative).to eq file_set
end
end

context 'when the representative is already set' do
let(:rep) { build(:file_set, id: '123') }

it 'keeps the existing representative' do
expect(work.representative).to eq rep
end
end
end

describe "#set_thumbnail" do
let!(:work) { build(:generic_work, thumbnail: thumb) }
let!(:file_set) { build(:file_set) }

before do
actor.send(:set_thumbnail, work, file_set)
end

context "when the thumbnail isn't set" do
let(:thumb) { nil }

it 'sets the thumbnail' do
expect(work.thumbnail).to eq file_set
end
end

context 'when the thumbnail is already set' do
let(:thumb) { build(:file_set, id: '123') }

it 'keeps the existing thumbnail' do
expect(work.thumbnail).to eq thumb
end
end
end
end

0 comments on commit 05c12be

Please sign in to comment.