diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb index 9e048ca87bf..375a5407e58 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_form.rb @@ -4,7 +4,7 @@ module AccreditedRepresentativePortal class PowerOfAttorneyForm < ApplicationRecord belongs_to :power_of_attorney_request, class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest', - inverse_of: :form + inverse_of: :power_of_attorney_form has_kms_key @@ -15,10 +15,6 @@ class PowerOfAttorneyForm < ApplicationRecord blind_index :zipcode # Validations - validates :power_of_attorney_request_id, uniqueness: true validates :data_ciphertext, presence: true - validates :city_bidx, presence: true, length: { is: 44 } - validates :state_bidx, presence: true, length: { is: 44 } - validates :zipcode_bidx, presence: true, length: { is: 44 } end end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb index 0d796feaa62..18af415b22c 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request.rb @@ -2,20 +2,14 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequest < ApplicationRecord - belongs_to :claimant, - class_name: 'UserAccount' + belongs_to :claimant, class_name: 'UserAccount' - has_one :form, + has_one :power_of_attorney_form, class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyForm', - inverse_of: :power_of_attorney_request, - dependent: :destroy + inverse_of: :power_of_attorney_request has_one :resolution, class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution', - inverse_of: :power_of_attorney_request, - dependent: :destroy - - # Validations - validates :created_at, presence: true + inverse_of: :power_of_attorney_request end end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb index 76cbae91d9e..0f7d0fcc749 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_decision.rb @@ -2,14 +2,13 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestDecision < ApplicationRecord + include PowerOfAttorneyRequestResolution::Resolving + + self.inheritance_column = nil + belongs_to :creator, class_name: 'UserAccount' - has_one :power_of_attorney_request_resolution, - as: :resolving, - inverse_of: :resolving, - dependent: :destroy - - validates :type, presence: true, length: { maximum: 255 } + validates :type, presence: true end end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb index 56c88e674c7..a2a6fd4cd9e 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_expiration.rb @@ -2,12 +2,6 @@ module AccreditedRepresentativePortal class PowerOfAttorneyRequestExpiration < ApplicationRecord - has_one :power_of_attorney_request_resolution, - as: :resolving, - inverse_of: :resolving, - dependent: :destroy - - # Validations - validates :id, presence: true + include PowerOfAttorneyRequestResolution::Resolving end end diff --git a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb index d3a9835455f..6728f1d5dfe 100644 --- a/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb +++ b/modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb @@ -22,5 +22,17 @@ class PowerOfAttorneyRequestResolution < ApplicationRecord validates :resolving_type, presence: true, inclusion: { in: RESOLVING_TYPES, allow_nil: true } validates :resolving_id, presence: true, if: -> { resolving_type.present? } validates :created_at, presence: true + + module Resolving + extend ActiveSupport::Concern + + included do + has_one( + :power_of_attorney_request_resolution, + as: :resolving, + touch: true + ) + end + end end end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb index 22d349918f4..fd5d8a69418 100644 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb +++ b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_form_spec.rb @@ -8,18 +8,7 @@ end describe 'validations' do - it 'validates uniqueness of power_of_attorney_request_id' do - form = create(:power_of_attorney_form) - duplicate_form = build(:power_of_attorney_form, power_of_attorney_request: form.power_of_attorney_request) - - expect(duplicate_form).not_to be_valid - expect(duplicate_form.errors[:power_of_attorney_request_id]).to include('has already been taken') - end - it { is_expected.to validate_presence_of(:data_ciphertext) } - it { is_expected.to validate_length_of(:city_bidx).is_equal_to(44) } - it { is_expected.to validate_length_of(:state_bidx).is_equal_to(44) } - it { is_expected.to validate_length_of(:zipcode_bidx).is_equal_to(44) } end describe 'creation' do diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb index bcb488b408c..f455f6849e2 100644 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb +++ b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_decision_spec.rb @@ -5,19 +5,6 @@ RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision, type: :model do describe 'associations' do it { is_expected.to belong_to(:creator).class_name('UserAccount') } - it { is_expected.to have_one(:power_of_attorney_request_resolution).dependent(:destroy) } - end - - describe 'validations' do - it { is_expected.to validate_presence_of(:type) } - it { is_expected.to validate_length_of(:type).is_at_most(255) } - end - - describe 'creation' do - it 'creates a valid record' do - user = UserAccount.create!(id: SecureRandom.uuid) - decision = build(:power_of_attorney_request_decision, creator: user) - expect(decision).to be_valid - end + it { is_expected.to have_one(:power_of_attorney_request_resolution) } end end diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb index 5664afacbaf..6c6374b63fa 100644 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb +++ b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_expiration_spec.rb @@ -4,7 +4,7 @@ RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration, type: :model do describe 'associations' do - it { is_expected.to have_one(:power_of_attorney_request_resolution).dependent(:destroy) } + it { is_expected.to have_one(:power_of_attorney_request_resolution) } end describe 'validations' do diff --git a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb index f804b1e7ced..4930a7fcda2 100644 --- a/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb +++ b/modules/accredited_representative_portal/spec/models/accredited_representative_portal/power_of_attorney_request_spec.rb @@ -5,19 +5,7 @@ RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequest, type: :model do describe 'associations' do it { is_expected.to belong_to(:claimant).class_name('UserAccount') } - it { is_expected.to have_one(:form).dependent(:destroy) } - it { is_expected.to have_one(:resolution).dependent(:destroy) } - end - - describe 'validations' do - it { is_expected.to validate_presence_of(:created_at) } - end - - describe 'creation' do - it 'creates a valid record' do - user = UserAccount.create!(id: SecureRandom.uuid) - request = build(:power_of_attorney_request, claimant: user) - expect(request).to be_valid - end + it { is_expected.to have_one(:power_of_attorney_form) } + it { is_expected.to have_one(:resolution) } end end