Skip to content

Commit 4db5db6

Browse files
authored
Merge pull request #1281 from ElixirTeSS/fix-non-trainer-author-link
Fix 500 error when a person is linked to a non-trainer profile
2 parents 20329b7 + bb52f24 commit 4db5db6

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/helpers/materials_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def display_people(resource, attribute)
105105
display_attribute(resource, attribute) do |values|
106106
html = values.map do |person|
107107
if person.profile
108-
link_to(person.profile.full_name, person.profile)
108+
target = person.profile.is_a?(Trainer) ? person.profile : person.profile.user
109+
link_to(person.profile.full_name, target)
109110
elsif person.orcid.present?
110111
image_tag('ORCID-iD_icon_vector.svg', size: 16) + ' ' +
111112
external_link(person.display_name, person.orcid_url)

test/controllers/materials_controller_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,28 @@ class MaterialsControllerTest < ActionController::TestCase
16291629
end
16301630
end
16311631

1632+
test 'should display non-trainer contributor with linked ORCID' do
1633+
jc = profiles(:trainer_one_profile)
1634+
jc.update!(public: false, website: nil, image_url: nil)
1635+
jc = Profile.find(jc.id)
1636+
assert @material.update(authors: [{ name: 'John Doe' },
1637+
{ name: 'Jane Smith', orcid: '0000-0001-9999-9990' }],
1638+
contributors: [{ name: 'Jos Ca', orcid: '0000-0002-1825-0097' }])
1639+
1640+
get :show, params: { id: @material.id }
1641+
1642+
assert_select '.authors', text: 'Authors: John Doe, Jane Smith'
1643+
assert_select '.authors a', count: 1 do
1644+
assert_select '[href=?]', 'https://orcid.org/0000-0001-9999-9990'
1645+
end
1646+
1647+
assert_select '.contributors', { text: 'Contributors: Josiah Carberry' },
1648+
"Should use name from person's profile, if linked"
1649+
assert_select '.contributors a', count: 1 do
1650+
assert_select '[href=?]', user_path(jc.user)
1651+
end
1652+
end
1653+
16321654
test 'should update material authors using structured authors' do
16331655
sign_in @material.user
16341656
update = @updated_material.merge(authors: [

0 commit comments

Comments
 (0)