Skip to content

Commit

Permalink
Switch inheritance column to temp_type for ECF declarations
Browse files Browse the repository at this point in the history
Until we can safely backfill the `type` column, we are using `temp_type`, which
has already been backfilled and is kept up to date.
  • Loading branch information
ethax-ross committed Jan 14, 2025
1 parent e038a34 commit e56b4d8
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion app/models/participant_declaration/ecf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ParticipantDeclaration::ECF < ParticipantDeclaration
self.inheritance_column = :temp_type

has_many :statements, class_name: "Finance::Statement::ECF", through: :statement_line_items

validate :validate_against_profile_type
Expand All @@ -18,7 +20,7 @@ def uplift_paid?

def validate_against_profile_type
return unless participant_profile
return if participant_profile.type.demodulize == type.demodulize
return if participant_profile.type.demodulize == temp_type.demodulize

errors.add(:type, I18n.t(:declaration_type_must_match_profile_type))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class ParticipantDeclarationSerializer
include JSONAPI::Serializer

set_id :id

attribute :type
attribute :type, &:temp_type
attribute :participant_profile_id
attribute :cpd_lead_provider_id
attribute :declaration_type
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/finance/ecf/duplicate_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DuplicateSerializer
declaration_date: participant_declaration.declaration_date&.rfc3339,
course_identifier: participant_declaration.course_identifier,
evidence_held: participant_declaration.evidence_held,
type: participant_declaration.type,
type: participant_declaration.temp_type,
cpd_lead_provider: participant_declaration.cpd_lead_provider&.name,
state: participant_declaration.state,
superseded_by_id: participant_declaration.superseded_by_id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/v3/participant_declarations_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(cpd_lead_provider:, params:)
end

def participant_declarations_for_pagination
filterable_attributes = %i[id created_at user_id updated_at delivery_partner_id type]
filterable_attributes = %i[id created_at user_id updated_at delivery_partner_id temp_type]
scope = ParticipantDeclaration::ECF.union(
declarations_scope.select(*filterable_attributes),
ecf_previous_declarations_scope.select(*filterable_attributes),
Expand Down
4 changes: 2 additions & 2 deletions app/services/finance/ecf/assurance_report/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sql
pd.created_at AS declaration_created_at,
s.name AS statement_name,
s.id AS statement_id,
pd.type AS type
pd.temp_type AS temp_type
FROM participant_declarations pd
JOIN statement_line_items sli ON sli.participant_declaration_id = pd.id
JOIN statements s ON s.id = sli.statement_id
Expand Down Expand Up @@ -81,7 +81,7 @@ def sql
JOIN schools sc ON sc.id = latest_induction_record.school_id
LEFT OUTER JOIN ecf_participant_eligibilities epe ON epe.participant_profile_id = pp.id
JOIN delivery_partners dp ON dp.id = COALESCE(pd.delivery_partner_id, latest_induction_record.delivery_partner_id)
WHERE pd.type IN ('ParticipantDeclaration::ECT', 'ParticipantDeclaration::Mentor') AND #{where_values}
WHERE pd.temp_type IN ('ParticipantDeclaration::ECT', 'ParticipantDeclaration::Mentor') AND #{where_values}
ORDER BY u.full_name ASC
EOSQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/participants/_declarations_history.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

sl.with_row do |row|
row.with_key(text: "Type")
row.with_value(text: participant_declaration.type)
row.with_value(text: participant_declaration.temp_type)
end

sl.with_row do |row|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

sl.with_row do |row|
row.with_key(text: "Type")
row.with_value(text: participant_declaration.type)
row.with_value(text: participant_declaration.temp_type)
end

sl.with_row do |row|
Expand Down
4 changes: 2 additions & 2 deletions spec/models/participant_declaration/ecf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
it "raises an error when the declaration type is ECT and the profile type is Mentor" do
declaration = create(:mentor_participant_declaration)

declaration.type = "ParticipantDeclaration::ECT"
declaration.temp_type = "ParticipantDeclaration::ECT"

expect(declaration).to be_invalid
expect(declaration.errors[:type]).to include(I18n.t(:declaration_type_must_match_profile_type))
Expand All @@ -16,7 +16,7 @@
it "raises an error when the declaration type is Mentor and the profile type is ECT" do
declaration = create(:ect_participant_declaration)

declaration.type = "ParticipantDeclaration::Mentor"
declaration.temp_type = "ParticipantDeclaration::Mentor"

expect(declaration).to be_invalid
expect(declaration.errors[:type]).to include(I18n.t(:declaration_type_must_match_profile_type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
expect(data[:type]).to eq :participant_declaration

attrs = data[:attributes]
expect(attrs[:type]).to eq declaration.type
expect(attrs[:type]).to eq declaration.temp_type
expect(attrs[:participant_profile_id]).to eq declaration.participant_profile_id
expect(attrs[:cpd_lead_provider_id]).to eq declaration.cpd_lead_provider_id
expect(attrs[:declaration_type]).to eq declaration.declaration_type
Expand Down
2 changes: 1 addition & 1 deletion spec/services/finance/ecf/assurance_report/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
let!(:mentor_declaration) { travel_to(statement.deadline_date) { create(:mentor_participant_declaration, participant_profile: mentor_participant_profile, cpd_lead_provider:, delivery_partner:) } }

it { is_expected.to contain_exactly(participant_declaration, mentor_declaration) }
it { expect(subject.map(&:type)).to contain_exactly(/ECT/, /Mentor/) }
it { expect(subject.map(&:temp_type)).to contain_exactly(/ECT/, /Mentor/) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/services/record_declaration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
expected_type = participant_profile.mentor? ? "ParticipantDeclaration::Mentor" : "ParticipantDeclaration::ECT"

declaration = ParticipantDeclaration.last
expect(declaration.type).to eq(expected_type)
expect(declaration.temp_type).to eq(expected_type)
end

it "stores the correct data" do
Expand Down

0 comments on commit e56b4d8

Please sign in to comment.