generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split contract migration into two migrators
- Loading branch information
1 parent
07b008f
commit 13c4255
Showing
5 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Migration::Migrators | ||
class ContractTemplate < Base | ||
SHARED_ATTRIBUTES = %w[ | ||
created_at | ||
updated_at | ||
service_fee_percentage | ||
output_payment_percentage | ||
per_participant | ||
number_of_payment_periods | ||
recruitment_target | ||
service_fee_installments | ||
targeted_delivery_funding_per_participant | ||
monthly_service_fee | ||
special_course | ||
].freeze | ||
|
||
class << self | ||
def record_count | ||
ecf_contracts.count | ||
end | ||
|
||
def model | ||
:contract_template | ||
end | ||
|
||
def ecf_contracts | ||
Migration::Ecf::NpqContract.includes(:cohort, npq_lead_provider: [:cpd_lead_provider]) | ||
end | ||
end | ||
|
||
def call | ||
migrate(self.class.ecf_contracts) do |ecf_contract| | ||
contract_template = ::ContractTemplate.find_or_initialize_by(ecf_id: ecf_contract.id) | ||
contract_template.update!(ecf_contract.attributes.slice(*SHARED_ATTRIBUTES)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
spec/services/migration/migrators/contract_template_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Migration::Migrators::ContractTemplate do | ||
it_behaves_like "a migrator", :contract_template, [] do | ||
def create_ecf_resource | ||
cohort = create(:ecf_migration_cohort) | ||
npq_lead_provider = create(:ecf_migration_npq_lead_provider) | ||
course = create(:ecf_migration_npq_course) | ||
version = rand(1..9) | ||
|
||
create( | ||
:ecf_migration_statement, | ||
cpd_lead_provider: npq_lead_provider.cpd_lead_provider, | ||
cohort:, | ||
contract_version: "0.0.#{version}", | ||
) | ||
create( | ||
:ecf_migration_npq_contract, | ||
npq_lead_provider:, | ||
cohort:, | ||
course_identifier: course.identifier, | ||
version: "0.0.#{version}", | ||
created_at: rand(1..100).days.ago, | ||
updated_at: rand(1..100).days.ago, | ||
) | ||
end | ||
|
||
def create_npq_resource(ecf_resource); end | ||
|
||
def setup_failure_state | ||
# NPQ contract in ECF with a negative recruitment_target | ||
create( | ||
:ecf_migration_npq_contract, | ||
recruitment_target: -300, | ||
) | ||
end | ||
|
||
describe "#call" do | ||
it "sets the created ContractTemplate attributes correctly" do | ||
instance.call | ||
|
||
contract_template = ContractTemplate.find_by!(ecf_id: ecf_resource1.id) | ||
attrs = ecf_resource1.attributes.slice(*described_class::SHARED_ATTRIBUTES) | ||
expect(contract_template).to have_attributes(attrs) | ||
end | ||
end | ||
end | ||
end |