Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Publication < ApplicationRecord
has_one :content_blob, ->(r) { where('content_blobs.asset_version =? AND deleted=?', r.version, false) }, as: :asset, foreign_key: :asset_id

explicit_versioning(:version_column => "version", sync_ignore_columns: ['license','other_creators']) do
acts_as_versioned_resource
acts_as_versioned_resource
has_one :content_blob, -> (r) { where('content_blobs.asset_version =? AND content_blobs.asset_type =?', r.version, r.parent.class.name) },
:primary_key => :publication_id,:foreign_key => :asset_id

Expand All @@ -58,7 +58,7 @@ def doi_uri
end

alias_method :doi_identifier, :doi_uri
end
end

belongs_to :publication_type

Expand All @@ -78,6 +78,8 @@ def doi_uri

accepts_nested_attributes_for :publication_authors

auto_strip_attributes :abstract

# Types of registration
REGISTRATION_BY_PUBMED = 1
REGISTRATION_BY_DOI = 2
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/seek_upgrades.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace :seek do
update_rdf
update_morpheus_model
db:seed:018_discipline_vocab
strip_publication_abstracts
]

# these are the tasks that are executes for each upgrade as standard, and rarely change
Expand Down Expand Up @@ -98,6 +99,18 @@ namespace :seek do
end
end

task(strip_publication_abstracts: [:environment]) do
puts 'Stripping publication abstracts...'
Publication.select(:id, :abstract).find_each do |publication|
if publication.abstract.present?
stripped = publication.abstract.strip
if stripped.length != publication.abstract.length
publication.update_column(:abstract, stripped)
end
end
end
end

private

##
Expand Down
45 changes: 45 additions & 0 deletions test/unit/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,49 @@ class PublicationTest < ActiveSupport::TestCase
assert_includes publication.related_models, assay_model
assert_includes publication.related_models, model
end

test 'strips leading and trailing whitespace from abstract on save' do
publication = FactoryBot.build(:publication, abstract:
" \n This is an abstract with leading and trailing whitespace \n ")

User.with_current_user(publication.contributor) do
publication.save!
end

assert_equal 'This is an abstract with leading and trailing whitespace', publication.abstract
end

test 'handles nil abstract gracefully' do
publication = FactoryBot.build(:publication, abstract: nil)

User.with_current_user(publication.contributor) do
publication.save!
end

assert_nil publication.abstract
end

test 'strips whitespace from abstract when extracted from pubmed' do
publication_hash = {
'title' => 'SEEK publication',
'abstract' => " An investigation into blalblabla \n ",
'journal' => 'The testing journal',
'pubmed' => '12345',
'doi' => nil
}
bio_reference = Bio::Reference.new(publication_hash)
publication = Publication.new(
title: 'Test',
projects: [FactoryBot.create(:project)],
publication_type: FactoryBot.create(:journal)
)

publication.extract_pubmed_metadata(bio_reference)

User.with_current_user(FactoryBot.create(:person).user) do
publication.save!
end

assert_equal 'An investigation into blalblabla', publication.abstract
end
end
Loading