Skip to content

Commit

Permalink
(fix) Apply requested PR changes; all specs passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ojbucao committed Dec 17, 2024
1 parent 6024452 commit 7ec1183
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7ec1183

Please sign in to comment.