diff --git a/app/models/accredited_individual.rb b/app/models/accredited_individual.rb index 86bebe29aea..4c4c83aae0b 100644 --- a/app/models/accredited_individual.rb +++ b/app/models/accredited_individual.rb @@ -26,7 +26,8 @@ class AccreditedIndividual < ApplicationRecord has_many :power_of_attorney_requests, as: :power_of_attorney_holder, inverse_of: :power_of_attorney_holder, - class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest' + class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest', + dependent: :restrict_with_exception validates :ogc_id, :registration_number, :individual_type, presence: true validates :poa_code, length: { is: 3 }, allow_blank: true diff --git a/app/models/accredited_organization.rb b/app/models/accredited_organization.rb index 312a9acf366..021850a1b64 100644 --- a/app/models/accredited_organization.rb +++ b/app/models/accredited_organization.rb @@ -22,7 +22,8 @@ class AccreditedOrganization < ApplicationRecord has_many :power_of_attorney_requests, as: :power_of_attorney_holder, inverse_of: :power_of_attorney_holder, - class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest' + class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest', + dependent: :restrict_with_exception validates :ogc_id, :poa_code, presence: true validates :poa_code, length: { is: 3 } diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/accredited_individual_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/accredited_individual_serializer.rb index e72529559c0..3a9bd7916d5 100644 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/accredited_individual_serializer.rb +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/accredited_individual_serializer.rb @@ -10,7 +10,7 @@ class AccreditedIndividualSerializer < ApplicationSerializer poa_holder.last_name ] - parts.reject(&:blank?).join(' ') + parts.compact_blank.join(' ') end end end diff --git a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/power_of_attorney_holder_serializer.rb b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/power_of_attorney_holder_serializer.rb index bec5719076f..e898bb14840 100644 --- a/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/power_of_attorney_holder_serializer.rb +++ b/modules/accredited_representative_portal/app/serializers/accredited_representative_portal/power_of_attorney_request_serializer/power_of_attorney_holder_serializer.rb @@ -24,7 +24,7 @@ class PowerOfAttorneyHolderSerializer < ApplicationSerializer poa_holder.last_name ] - parts.reject(&:blank?).join(' ') + parts.compact_blank.join(' ') end end end diff --git a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb index a421ce16bc1..ac3ad6c8916 100644 --- a/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb +++ b/modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb @@ -5,7 +5,7 @@ association :claimant, factory: :user_account association :power_of_attorney_form, strategy: :build - association :power_of_attorney_holder, factory: [:accredited_organization, :with_representatives] + association :power_of_attorney_holder, factory: %i[accredited_organization with_representatives] accredited_individual { power_of_attorney_holder.accredited_individuals.first } trait :with_acceptance do diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb index 92a75148a7e..a0c4a0f40c1 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/power_of_attorney_requests_spec.rb @@ -95,7 +95,10 @@ }, 'accredited_individual' => { 'id' => poa_requests[0].accredited_individual.id, - 'full_name' => "#{poa_requests[0].accredited_individual.first_name} #{poa_requests[0].accredited_individual.last_name}", + 'full_name' => [ + poa_requests[0].accredited_individual.first_name, + poa_requests[0].accredited_individual.last_name + ].join(' ') }, 'resolution' => nil }, @@ -161,7 +164,10 @@ }, 'accredited_individual' => { 'id' => poa_requests[1].accredited_individual.id, - 'full_name' => "#{poa_requests[1].accredited_individual.first_name} #{poa_requests[1].accredited_individual.last_name}", + 'full_name' => [ + poa_requests[1].accredited_individual.first_name, + poa_requests[1].accredited_individual.last_name + ].join(' ') }, 'resolution' => { 'id' => poa_requests[1].resolution.id, @@ -233,7 +239,10 @@ }, 'accredited_individual' => { 'id' => poa_requests[2].accredited_individual.id, - 'full_name' => "#{poa_requests[2].accredited_individual.first_name} #{poa_requests[2].accredited_individual.last_name}", + 'full_name' => [ + poa_requests[2].accredited_individual.first_name, + poa_requests[2].accredited_individual.last_name + ].join(' ') }, 'resolution' => { 'id' => poa_requests[2].resolution.id, @@ -306,7 +315,10 @@ }, 'accredited_individual' => { 'id' => poa_requests[3].accredited_individual.id, - 'full_name' => "#{poa_requests[3].accredited_individual.first_name} #{poa_requests[3].accredited_individual.last_name}", + 'full_name' => [ + poa_requests[3].accredited_individual.first_name, + poa_requests[3].accredited_individual.last_name + ].join(' ') }, 'resolution' => { 'id' => poa_requests[3].resolution.id, @@ -397,7 +409,10 @@ }, 'accredited_individual' => { 'id' => poa_request.accredited_individual.id, - 'full_name' => "#{poa_request.accredited_individual.first_name} #{poa_request.accredited_individual.last_name}", + 'full_name' => [ + poa_request.accredited_individual.first_name, + poa_request.accredited_individual.last_name + ].join(' ') } } )