Skip to content

Commit 10f9378

Browse files
authored
Deduplicate department field from requests (#2229)
ref #2147
1 parent 7782176 commit 10f9378

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/controllers/request_wizards_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def request_params
112112
:requested_by, :storage_size, :storage_unit, :number_of_files, :hpc, :smb, :globus, user_roles: [], departments: [])
113113
request_params[:storage_unit] ||= "TB"
114114
if request_params[:departments].present?
115-
request_params[:departments] = request_params[:departments].compact_blank.map { |dep_str| JSON.parse(dep_str) }
115+
request_params[:departments] = clean_departments(request_params[:departments])
116116
end
117117
if request_params[:user_roles].present?
118118
request_params[:user_roles] = request_params[:user_roles].compact_blank.map do |role_str|
@@ -124,6 +124,11 @@ def request_params
124124
request_params
125125
end
126126

127+
def clean_departments(departments)
128+
uniq_departments = departments.uniq
129+
uniq_departments.compact_blank.map { |dep_str| JSON.parse(dep_str) }
130+
end
131+
127132
def set_breadcrumbs
128133
add_breadcrumb("Dashboard", dashboard_path)
129134
end

spec/system/new_project_request_wizard_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,39 @@
331331
end.to change { Request.count }.by(1)
332332
end
333333

334+
it "does not allow requests to be submitted with duplicate departments." do
335+
Affiliation.load_from_file(Rails.root.join("spec", "fixtures", "departments.csv"))
336+
sign_in current_user
337+
visit "new-project/project-info"
338+
339+
# Non breaking space `u00A0` is at the end of every option to indicate an option was selected
340+
select "(77777) RDSS-Research Data and Scholarship Services\u00A0", from: "department_find"
341+
select "(77777) RDSS-Research Data and Scholarship Services\u00A0", from: "department_find"
342+
# This is triggering the html5 element like it would normally if the page has focus
343+
page.find(:datalist_input, "department_find").execute_script("document.getElementById('department_find').dispatchEvent(new Event('input'))")
344+
expect(page).to have_field("request[departments][]", type: :hidden, with: "{\"code\":\"77777\",\"name\":\"RDSS-Research Data and Scholarship Services\"}")
345+
expect(page).to have_content("(77777) RDSS-Research Data and Scholarship Services").exactly(2).times
346+
347+
click_on "Review and Submit"
348+
expect(page).to have_content("Take a moment to review your details and make any necessary edits before finalizing.")
349+
expect(page).to have_content("(77777) RDSS-Research Data and Scholarship Services").exactly(1).times
350+
351+
fill_in :project_title, with: "No Duplicate Departments Project"
352+
fill_in :parent_folder, with: "abc_lab"
353+
fill_in :project_folder, with: "skeletor"
354+
fill_in :description, with: "An awesome project to show the wizard is magic"
355+
select "Research", from: "project_purpose"
356+
select_user(current_user, "data_sponsor", "request[data_sponsor]")
357+
select_user(current_user, "data_manager", "request[data_manager]")
358+
359+
click_on "Submit"
360+
expect(page).to have_content("Your new project request is submitted")
361+
362+
visit "requests/#{Request.last.id}"
363+
expect(page).to have_content("No Duplicate Departments Project")
364+
expect(page).to have_content("RDSS-Research Data and Scholarship Services").exactly(1).times
365+
end
366+
334367
it "allows for save and exit" do
335368
sign_in current_user
336369
visit "/"

0 commit comments

Comments
 (0)