From 338aa717d22c6068e0c2b602df3b86d0d0fac4c1 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Wed, 20 Dec 2023 15:37:29 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Fix=20`./spec/requests/admin=5Fd?= =?UTF-8?q?ashboard=5Fspec.rb`=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this commit, the specs failed because of the introduction of the WorkflowResponsibilityFormDecorator. The decorator extracted prior logic from Hyrax::Admin::WorkflowRolesController. In copying that logic we introduced a subtle bug. Namely, we favored the original `.new` behavior if and only if you provided a `:user_id`. This broke places where we instantiated the form in a view (e.g. `./app/views/hyrax/admin/workflow_roles/index.html.erb`). With this change, we make the behavior of `.new` fail towards its "normal" implementation and instead rely on the presence of an attribute to switch to a different form instantatior. See Commit: - https://github.com/samvera/hyku/commit/095edca9a50e647eb1b3ee31a34711c32151912e Related to: - https://github.com/samvera/hyku/pull/2079 Co-authored-by: LaRita Robinson Co-authored-by: Kirk Wang --- .../workflow_responsibility_form_decorator.rb | 16 ++++++++++++---- .../forms/workflow_responsibility_group_form.rb | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/forms/hyrax/forms/workflow_responsibility_form_decorator.rb b/app/forms/hyrax/forms/workflow_responsibility_form_decorator.rb index 10fc33a32..87119cdba 100644 --- a/app/forms/hyrax/forms/workflow_responsibility_form_decorator.rb +++ b/app/forms/hyrax/forms/workflow_responsibility_form_decorator.rb @@ -5,13 +5,21 @@ module Hyrax module Forms module WorkflowResponsibilityFormDecorator + ## + # @note We introduced this little crease in the code to allow for conditional switching; and + # thus avoid copying a very large controller + # (e.g. Hyrax::Admin::WorkflowRolesController) + # @see Hyrax::Forms::WorkflowResponsibilityGroupForm module ClassMethods - # Determine which form it is, user or group + ## + # Determine which form it is, user or group. By default, it will be a user + # (e.g. {Hyrax::Forms::WorkflowResponsibilityForm}); however when you provide a :group_id it + # will be a group form (e.g. {Hyrax::Forms::WorkflowResponsibilityGroupForm}. def new(params = {}) - if params[:user_id].present? - super - else + if params[:group_id].present? Forms::WorkflowResponsibilityGroupForm.new(params) + else + super end end end diff --git a/app/forms/hyrax/forms/workflow_responsibility_group_form.rb b/app/forms/hyrax/forms/workflow_responsibility_group_form.rb index 71f4323fb..7cb6d0715 100644 --- a/app/forms/hyrax/forms/workflow_responsibility_group_form.rb +++ b/app/forms/hyrax/forms/workflow_responsibility_group_form.rb @@ -10,6 +10,11 @@ def initialize(params = {}) model_instance.agent = group.to_sipity_agent end + ## + # This method is necessary for the HTML form fields to have the correct name (e.g. ``). + # + # @see ActiveModel::Naming def model_instance @model ||= Sipity::WorkflowResponsibility.new end