Skip to content

Commit 6f6fbb6

Browse files
committed
Fix param conversion issue
1 parent c2e8085 commit 6f6fbb6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/models/concerns/has_people.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def set_people_for_role(value, role_name, role_key)
2626
current_people = send(role_name).to_a
2727
to_keep = []
2828

29-
Array(value).reject(&:blank?).map do |person_data|
29+
value = value.values if value.respond_to?(:keys) && value.keys.first.match(/\A\d+\z/)
30+
Array.wrap(value).reject(&:blank?).map do |person_data|
3031
person_data = person_data.to_h if person_data.is_a?(ActionController::Parameters)
3132
if person_data.is_a?(String)
3233
attrs = { name: person_data.strip }

test/controllers/materials_controller_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,4 +1659,17 @@ class MaterialsControllerTest < ActionController::TestCase
16591659
assert_equal 'Joe', mat.authors.first[:name]
16601660
assert_nil mat.authors.first[:orcid]
16611661
end
1662+
1663+
test 'should update material authors using param structured authors' do
1664+
material = materials(:material_with_optionals)
1665+
sign_in material.user
1666+
update = { authors: { '1234' => {
1667+
name: 'Joe', orcid: '0000-0002-1825-0097' } } }
1668+
patch :update, params: { id: material, material: update }
1669+
mat = assigns(:material)
1670+
assert_redirected_to material_path(mat)
1671+
1672+
assert_equal 'Joe', mat.authors.first[:name]
1673+
assert_equal '0000-0002-1825-0097', mat.authors.first[:orcid]
1674+
end
16621675
end

0 commit comments

Comments
 (0)