From 651217c819e1b660b9dad8db579ae5c6792f085e Mon Sep 17 00:00:00 2001 From: Steve Hook Date: Tue, 17 Oct 2023 09:30:10 +0100 Subject: [PATCH] Refactored to move logic from view helper --- ...ication_dashboard_course_choices_component.rb | 7 +------ .../application_status_tag_component.rb | 4 ++-- .../application_review_component.rb | 6 +----- .../application_summary_component.rb | 7 +------ .../course_choices_review_component.rb | 7 +------ .../previous_applications_component.html.erb | 7 +------ .../rejection_reasons_component.rb | 7 +------ .../application_card_component.html.erb | 7 +------ .../application_choice_header_component.html.erb | 7 +------ .../application_status_tag_component.rb | 4 ++-- .../application_card_component.html.erb | 9 +-------- .../application_choice_component.rb | 7 +------ .../application_status_tag_component.rb | 7 ++++--- app/helpers/view_helper.rb | 9 --------- app/models/application_choice.rb | 8 ++++++++ .../recruit_with_pending_conditions/new.html.erb | 1 - .../application_status_tag_component_spec.rb | 8 ++++---- .../application_status_tag_component_spec.rb | 9 ++++++--- .../application_status_tag_component_spec.rb | 9 +++++++-- spec/helpers/view_helper_spec.rb | 14 -------------- spec/models/application_choice_spec.rb | 16 ++++++++++++++++ 21 files changed, 59 insertions(+), 101 deletions(-) diff --git a/app/components/candidate_interface/application_dashboard_course_choices_component.rb b/app/components/candidate_interface/application_dashboard_course_choices_component.rb index 59a50d09173..9363734f04c 100644 --- a/app/components/candidate_interface/application_dashboard_course_choices_component.rb +++ b/app/components/candidate_interface/application_dashboard_course_choices_component.rb @@ -149,12 +149,7 @@ def status_row(application_choice) if @show_status { key: 'Status', - value: render( - ApplicationStatusTagComponent.new( - application_choice:, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ), + value: render(ApplicationStatusTagComponent.new(application_choice:)), } end end diff --git a/app/components/candidate_interface/application_status_tag_component.rb b/app/components/candidate_interface/application_status_tag_component.rb index 476308c861d..e984bc65735 100644 --- a/app/components/candidate_interface/application_status_tag_component.rb +++ b/app/components/candidate_interface/application_status_tag_component.rb @@ -2,10 +2,10 @@ module CandidateInterface class ApplicationStatusTagComponent < ViewComponent::Base delegate :status, to: :application_choice - def initialize(application_choice:, display_info_text: true, supplementary_statuses: []) + def initialize(application_choice:, display_info_text: true) @application_choice = application_choice @display_info_text = display_info_text - @supplementary_statuses = supplementary_statuses + @supplementary_statuses = application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : [] end def text diff --git a/app/components/candidate_interface/continuous_applications/application_review_component.rb b/app/components/candidate_interface/continuous_applications/application_review_component.rb index 950294c9777..4b94cfa36ff 100644 --- a/app/components/candidate_interface/continuous_applications/application_review_component.rb +++ b/app/components/candidate_interface/continuous_applications/application_review_component.rb @@ -28,11 +28,7 @@ def status_row { key: 'Status', value: render( - ApplicationStatusTagComponent.new( - application_choice:, - display_info_text: false, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), + ApplicationStatusTagComponent.new(application_choice:, display_info_text: false), ), } end diff --git a/app/components/candidate_interface/continuous_applications/application_summary_component.rb b/app/components/candidate_interface/continuous_applications/application_summary_component.rb index a13969fc681..01b71a7d36a 100644 --- a/app/components/candidate_interface/continuous_applications/application_summary_component.rb +++ b/app/components/candidate_interface/continuous_applications/application_summary_component.rb @@ -70,12 +70,7 @@ def course_details def application_choice_status_row { key: 'Status', - value: render( - ContinuousApplications::ApplicationStatusTagComponent.new( - application_choice:, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ), + value: render(ContinuousApplications::ApplicationStatusTagComponent.new(application_choice:)), } end end diff --git a/app/components/candidate_interface/course_choices_review_component.rb b/app/components/candidate_interface/course_choices_review_component.rb index 63ab2c69cb3..7de57c5c913 100644 --- a/app/components/candidate_interface/course_choices_review_component.rb +++ b/app/components/candidate_interface/course_choices_review_component.rb @@ -270,12 +270,7 @@ def status_row(application_choice) if @show_status { key: 'Status', - value: render( - ApplicationStatusTagComponent.new( - application_choice:, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ), + value: render(ApplicationStatusTagComponent.new(application_choice:)), } end end diff --git a/app/components/candidate_interface/previous_applications_component.html.erb b/app/components/candidate_interface/previous_applications_component.html.erb index adc4d383661..b64937873a2 100644 --- a/app/components/candidate_interface/previous_applications_component.html.erb +++ b/app/components/candidate_interface/previous_applications_component.html.erb @@ -22,12 +22,7 @@ <% end %> - <%= - render CandidateInterface::ApplicationStatusTagComponent.new( - application_choice: application_choice, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ) - %> + <%= render CandidateInterface::ApplicationStatusTagComponent.new(application_choice:) %> <% end %> diff --git a/app/components/candidate_interface/rejection_reasons_component.rb b/app/components/candidate_interface/rejection_reasons_component.rb index 6285fad73a7..51220bb4b20 100644 --- a/app/components/candidate_interface/rejection_reasons_component.rb +++ b/app/components/candidate_interface/rejection_reasons_component.rb @@ -40,12 +40,7 @@ def course_details_row_value(application_choice) def status_row(application_choice) { key: 'Status', - value: render( - ApplicationStatusTagComponent.new( - application_choice:, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ), + value: render(ApplicationStatusTagComponent.new(application_choice:)), } end diff --git a/app/components/provider_interface/application_card_component.html.erb b/app/components/provider_interface/application_card_component.html.erb index 053ad4d0a6b..2c7e7276fb6 100644 --- a/app/components/provider_interface/application_card_component.html.erb +++ b/app/components/provider_interface/application_card_component.html.erb @@ -7,12 +7,7 @@ - <%= render( - ProviderInterface::ApplicationStatusTagComponent.new( - application_choice: application_choice, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ) %> + <%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice:)) %> diff --git a/app/components/provider_interface/application_choice_header_component.html.erb b/app/components/provider_interface/application_choice_header_component.html.erb index 0d0fdc29579..6e91df1135a 100644 --- a/app/components/provider_interface/application_choice_header_component.html.erb +++ b/app/components/provider_interface/application_choice_header_component.html.erb @@ -1,12 +1,7 @@

<%= application_choice.application_form.full_name %> - <%= render( - ProviderInterface::ApplicationStatusTagComponent.new( - application_choice: application_choice, - supplementary_statuses: supplementary_statuses_for(application_choice:), - ), - ) %> + <%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice:)) %>

diff --git a/app/components/provider_interface/application_status_tag_component.rb b/app/components/provider_interface/application_status_tag_component.rb index 101131f70b0..86583f38434 100644 --- a/app/components/provider_interface/application_status_tag_component.rb +++ b/app/components/provider_interface/application_status_tag_component.rb @@ -2,9 +2,9 @@ module ProviderInterface class ApplicationStatusTagComponent < ViewComponent::Base delegate :status, to: :application_choice - def initialize(application_choice:, supplementary_statuses: []) + def initialize(application_choice:) @application_choice = application_choice - @supplementary_statuses = supplementary_statuses + @supplementary_statuses = application_choice.respond_to?(:supplementary_statuses) ? application_choice.supplementary_statuses : [] end def text diff --git a/app/components/support_interface/application_card_component.html.erb b/app/components/support_interface/application_card_component.html.erb index bc5e2249834..0ec2f914fa5 100644 --- a/app/components/support_interface/application_card_component.html.erb +++ b/app/components/support_interface/application_card_component.html.erb @@ -11,14 +11,7 @@