From 434074af017bac2d1541be60ee76626b0a125d14 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Thu, 13 Feb 2025 11:08:50 -0700 Subject: [PATCH 1/4] Add feature test for research_output associations This adds test coverage for a previously undetected Rails 7 breaking change affecting nested attribute params structure in `hidden_field_tag` --- spec/features/modal_search_spec.rb | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/features/modal_search_spec.rb b/spec/features/modal_search_spec.rb index f4df729692..f2da470a71 100644 --- a/spec/features/modal_search_spec.rb +++ b/spec/features/modal_search_spec.rb @@ -49,4 +49,35 @@ click_link 'Remove' expect(page).not_to have_text(@model.description) end + + it 'saves research output and selected repository association', :js do + # Fill in required fields + fill_in 'Title', with: 'Test Output' + select 'Audiovisual', from: 'research_output_output_type' + + # Open the modal and select repository + click_button 'Add a repository' + within('#modal-search-repositories') do + fill_in 'research_output_search_term', with: @model.name + click_button 'Apply filter(s)' + click_link 'Select' + modal_close_button = find('.modal-header button.btn-close') + execute_script('arguments[0].click();', modal_close_button) + end + + click_button 'Save' + + # Verify UI changes + expect(page).to have_css('.fas.fa-circle-check + span + span', + text: 'Successfully added the researchoutput.') + expect(page).to have_content('Test Output') + expect(page).to have_content(@model.name) + + # Verify DB changes + research_output = ResearchOutput.last + expect(research_output.title).to eq('Test Output') + expect(research_output.output_type).to eq('audiovisual') + expect(research_output.repositories).to include(@model) + expect(research_output.plan).to eq(@plan) + end end From b417f28e634ad91b1207261bc3885d62a868273d Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Thu, 13 Feb 2025 11:49:04 -0700 Subject: [PATCH 2/4] Fix `hidden_field_tag` params for Rails 7 upgrade This change addresses a breaking issue introduced by the Rails 7 upgrade, where the hidden_field_tag parameters for nested attributes were not being processed correctly. The parameter structure has been updated to match Rails 7's expected format, ensuring proper handling of nested associations. --- .../research_outputs/metadata_standards/_search_result.html.erb | 2 +- app/views/research_outputs/repositories/_search_result.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/research_outputs/metadata_standards/_search_result.html.erb b/app/views/research_outputs/metadata_standards/_search_result.html.erb index 9d8ed5e102..5ec6059f2e 100644 --- a/app/views/research_outputs/metadata_standards/_search_result.html.erb +++ b/app/views/research_outputs/metadata_standards/_search_result.html.erb @@ -1,7 +1,7 @@ <%# locals: result %> <% if result.present? %> - <%= hidden_field_tag "research_output[metadata_standards_attributes[#{result.id}][id]]", result.id %> + <%= hidden_field_tag "research_output[metadata_standards_attributes][#{result.id}][id]", result.id %>

<%= sanitize(result.description) %>

diff --git a/app/views/research_outputs/repositories/_search_result.html.erb b/app/views/research_outputs/repositories/_search_result.html.erb index f15efab19e..1b01303a22 100644 --- a/app/views/research_outputs/repositories/_search_result.html.erb +++ b/app/views/research_outputs/repositories/_search_result.html.erb @@ -3,7 +3,7 @@ %> <% if result.present? %> - <%= hidden_field_tag "research_output[repositories_attributes[#{result.id}][id]]", result.id %> + <%= hidden_field_tag "research_output[repositories_attributes][#{result.id}][id]", result.id %>

<%= result.description %>

From 527c3475c33f01a074ea1a81d108b5d45fe248d8 Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Thu, 13 Feb 2025 12:37:25 -0700 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ace50817c5..cc8ddb1060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field. - Fixed bar chart click function in the Usage dashboard (GitHub issue #3443) - Fixed broken link for the V1 API documentation. +- Fix `hidden_field_tag` Nested Attributes Format For Rails 7 Upgrade and Add Test Coverage [#3479](https://github.com/DMPRoadmap/roadmap/pull/3479) **Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** From 8a7d8328e7498c7b1a08861c187e6b599844db2e Mon Sep 17 00:00:00 2001 From: aaronskiba Date: Thu, 13 Feb 2025 15:36:48 -0700 Subject: [PATCH 4/4] Fix GH Action test: `data-bs-dismiss` modal close `execute_script('arguments[0].click();', modal_close_button)` works locally, however, the modal seems to be failing to close when the test is run as a GitHub Action. - Strangely `execute_script('arguments[0].click();', modal_close_button)` works as a GitHub Action when executed for the 'Modal search opens and closes and allows user to search, select and remove items' test within this same file. --- spec/features/modal_search_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/modal_search_spec.rb b/spec/features/modal_search_spec.rb index f2da470a71..8867e58a51 100644 --- a/spec/features/modal_search_spec.rb +++ b/spec/features/modal_search_spec.rb @@ -61,8 +61,8 @@ fill_in 'research_output_search_term', with: @model.name click_button 'Apply filter(s)' click_link 'Select' - modal_close_button = find('.modal-header button.btn-close') - execute_script('arguments[0].click();', modal_close_button) + # (execute_script('arguments[0].click();', modal_close_button) works locally here, but not as GitHub Action) + find('[data-bs-dismiss="modal"]').click end click_button 'Save'