Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Art/power of attorney request status updates.models #19600

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ Gem::Specification.new do |spec|

spec.files = Dir['{app,config,db,lib}/**/*', 'Rakefile', 'README.md']
spec.test_files = Dir['spec/**/*']

spec.add_development_dependency 'activerecord'
spec.add_development_dependency 'rspec-rails'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestDecision < ApplicationRecord
include PowerOfAttorneyRequestStatusUpdate::StatusUpdating

self.inheritance_column = nil
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestExpiration < ApplicationRecord
include PowerOfAttorneyRequestStatusUpdate::StatusUpdating
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestReplacement < ApplicationRecord
include PowerOfAttorneyRequestStatusUpdate::StatusUpdating
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestStatusUpdate < ApplicationRecord
delegated_type :status_updating, types: %w[
PowerOfAttorneyRequestReplacements
PowerOfAttorneyRequestExpirations
PowerOfAttorneyRequestWithdrawals
PowerOfAttorneyRequestDecisions
]

module StatusUpdating
extend ActiveSupport::Concern

included do
has_one(
:power_of_attorney_request_status_update,
as: :status_updating,
touch: true
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestWithdrawal < ApplicationRecord
include PowerOfAttorneyRequestStatusUpdate::StatusUpdating
end
end
9 changes: 6 additions & 3 deletions modules/accredited_representative_portal/bin/rails
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENGINE_ROOT = File.expand_path('../..', __dir__)
ENGINE_PATH = File.expand_path('../../lib/accredited_representative_portal/engine', __dir__)
require 'pathname'

ENGINE_ROOT = Pathname(__dir__).parent
ENGINE_PATH = ENGINE_ROOT / 'lib/accredited_representative_portal/engine'
BUNDLE_GEMFILE = ENGINE_ROOT / 'Gemfile'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
ENV['BUNDLE_GEMFILE'] ||= BUNDLE_GEMFILE.to_path
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class CreateArPowerOfAttorneyRequestStatusUpdates < ActiveRecord::Migration[7.1]
def change
create_table :ar_power_of_attorney_request_status_updates, id: :uuid do |t|
t.string 'status_updating_type', null: false
t.uuid 'status_updating_id', null: false
t.datetime 'created_at', null: false
end

create_table :ar_power_of_attorney_request_replacements, id: :uuid

create_table :ar_power_of_attorney_request_expirations, id: :uuid

create_table :ar_power_of_attorney_request_withdrawals, id: :uuid do |t|
t.text 'reason'
end

create_table :ar_power_of_attorney_request_decisions, id: :uuid do |t|
t.string 'type', null: false
t.text 'declination_reason'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,28 @@
module AccreditedRepresentativePortal
class Engine < ::Rails::Engine
isolate_namespace AccreditedRepresentativePortal

# `isolate_namespace` redefines `table_name_prefix` on load of
# `active_record`, so we append our own callback to redefine it again how we
# want.
ActiveSupport.on_load(:active_record) do
AccreditedRepresentativePortal.redefine_singleton_method(:table_name_prefix) do
'ar_'
end
end

config.generators.api_only = true

# So that the app-wide migration command notices our engine's migrations.
initializer :append_migrations do |app|
unless app.root.to_s.match? root.to_s
config.paths['db/migrate'].expanded.each do |expanded_path|
app.config.paths['db/migrate'] << expanded_path
ActiveRecord::Migrator.migrations_paths << expanded_path
end
end
end

initializer 'model_core.factories', after: 'factory_bot.set_factory_paths' do
FactoryBot.definition_file_paths << File.expand_path('../../spec/factories', __dir__) if defined?(FactoryBot)
end
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec directory has a type where "representatiive" with two i's

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# frozen_string_literal: true

require_relative '../../rails_helper'

mod = AccreditedRepresentativePortal
RSpec.describe mod::PowerOfAttorneyRequestStatusUpdate, type: :model do
it 'conveniently returns heterogeneous lists' do
travel_to '2024-11-25T09:46:24Z'

ids = []

ids <<
described_class.create!(
status_updating: mod::PowerOfAttorneyRequestDecision.new(
type: 'acceptance'
)
).id

ids <<
described_class.create!(
status_updating: mod::PowerOfAttorneyRequestDecision.new(
type: 'declination',
declination_reason: 'Some declination reason.'
)
).id

ids <<
described_class.create!(
status_updating: mod::PowerOfAttorneyRequestReplacement.new
).id

ids <<
described_class.create!(
status_updating: mod::PowerOfAttorneyRequestExpiration.new
).id

ids <<
described_class.create!(
status_updating: mod::PowerOfAttorneyRequestWithdrawal.new(
reason: 'Some withdrawal reason.'
)
).id

status_updates = described_class.includes(:status_updating).find(ids)

actual =
status_updates.map do |status_update|
serialized =
case status_update.status_updating
when mod::PowerOfAttorneyRequestDecision
{
type: 'decision',
decision_type: status_update.status_updating.type,
declination_reason: status_update.status_updating.declination_reason
}
when mod::PowerOfAttorneyRequestWithdrawal
{
type: 'withdrawal',
reason: status_update.status_updating.reason
}
when mod::PowerOfAttorneyRequestExpiration
{
type: 'expiration'
}
when mod::PowerOfAttorneyRequestReplacement
{
type: 'replacement'
}
end

serialized.merge!(
created_at: status_update.created_at.iso8601
)
end

expect(actual).to eq(
[
{
type: 'decision',
decision_type: 'acceptance',
declination_reason: nil,
created_at: '2024-11-25T09:46:24Z'
},
{
type: 'decision',
decision_type: 'declination',
declination_reason: 'Some declination reason.',
created_at: '2024-11-25T09:46:24Z'
},
{
type: 'replacement',
created_at: '2024-11-25T09:46:24Z'
},
{
type: 'expiration',
created_at: '2024-11-25T09:46:24Z'
},
{
type: 'withdrawal',
reason: 'Some withdrawal reason.',
created_at: '2024-11-25T09:46:24Z'
}
]
)
end
end
Loading