Skip to content

Commit

Permalink
saving the pub should come outside the find_or_create_by block (#1053)
Browse files Browse the repository at this point in the history
saving the pub should come outside the find_or_create_by block
  • Loading branch information
peetucket authored May 7, 2019
2 parents de57e1e + 13e142e commit f2bc17e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def assign_pub(pub)
cap_profile_id: cap_profile_id,
featured: false, status: 'new', visibility: 'private'
)
pub.pubhash_needs_update! # Add to pub_hash[:authorship]
pub.save! # contrib.save! not needed
end
pub.pubhash_needs_update! # Add to pub_hash[:authorship]
pub.save! # contrib.save! not needed
end

private
Expand Down
12 changes: 12 additions & 0 deletions spec/factories/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@
identifier_value: '10048354')
end
end

factory :publication_without_author, parent: :publication do
pub_hash do
{
title: title,
type: publication_type,
year: year,
author: [],
authorship: []
}
end
end
end
18 changes: 18 additions & 0 deletions spec/models/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,22 @@
expect(subject).not_to be_harvestable
end
end

describe '#assign_pub' do
let(:pub) { create :publication_without_author }

it 'creates contrib and updates pubhash' do
expect(subject.publications.count).to eq(0)
expect(subject.contributions.count).to eq(0)
expect(Publication.find(pub.id).pub_hash[:authorship].length).to eq(0)

subject.assign_pub(pub)
expect(subject.publications.count).to eq(1)
expect(subject.contributions.count).to eq(1)

# Verify that author added to publication
# See https://github.com/sul-dlss/sul_pub/issues/1052
expect(Publication.find(pub.id).pub_hash[:authorship].length).to eq(1)
end
end
end

0 comments on commit f2bc17e

Please sign in to comment.