Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/models/lead_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class LeadProvider < ApplicationRecord
"Church of England" => "79cb41ca-cb6d-405c-b52c-b6f7c752388d",
"LLSE" => "230e67c0-071a-4a48-9673-9d043d456281",
"National Institute of Teaching" => "3ec607f2-7a3a-421f-9f1a-9aca8a634aeb",
"School-Led Network" => "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0",
"Teach First" => "a02ae582-f939-462f-90bc-cebf20fa8473",
"UCL Institute of Education" => "ef687b3d-c1c0-4566-a295-16d6fa5d0fa7",
}.freeze
Expand All @@ -24,6 +23,7 @@ class LeadProvider < ApplicationRecord
validates :ecf_id, uniqueness: { case_sensitive: false }, allow_nil: true

scope :alphabetical, -> { order(name: :asc) }
scope :active, -> { where(ecf_id: ALL_ACTIVE_PROVIDERS.values) }

def self.for(course:, cohort: Cohort.current)
course_cohort = CourseCohort.find_by(course:, cohort:)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20221130142333_add_hint_to_lead_providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AddHintToLeadProviders < ActiveRecord::Migration[6.1]
def up
add_column :lead_providers, :hint, :string

school_led_network_lead_provider = LeadProvider.find_by(ecf_id: LeadProvider::ALL_ACTIVE_PROVIDERS["School-Led Network"])
school_led_network_lead_provider = LeadProvider.find_by(ecf_id: "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0")

school_led_network_lead_provider&.update!(
hint: "You can only register with this provider if you already started your NPQ with them in October 2022.",
Expand Down
1 change: 0 additions & 1 deletion db/seeds/base/add_api_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"Ambition Institute" => "ambition-token",
"Best Practice Network" => "best-practice-token",
"Church of England" => "coe-token",
"School-Led Network" => "school-led-token",
"UCL Institute of Education" => "ucl-token",
"Teach First" => "teach-first-token",
"National Institute of Teaching" => "niot-token",
Expand Down
59 changes: 59 additions & 0 deletions lib/tasks/one_off/update_statement_move_declarations_3678.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace :one_off do
desc "One off task for ticket NPQ-3678 to update statement and move declarations"
task :update_statement_move_declarations, %i[dry_run] => :versioned_environment do |_task, args|
Rails.logger = Logger.new($stdout) unless Rails.env.test?
dry_run = args[:dry_run] != "false"

Rails.logger.info "DRY RUN: will roll back at end" if dry_run

ActiveRecord::Base.transaction do
lead_providers = LeadProvider.active

lead_providers.each do |lead_provider|
statement = Statement.find_by(
month: 9,
year: 2026,
cohort: Cohort.find_by!(identifier: "2025a"),
lead_provider:,
)
statement.update!(output_fee: true)

Rails.logger.info "Set output_fee: true on #{statement.month}/#{statement.year} statement, cohort: #{statement.cohort.identifier}, lead provider: #{statement.lead_provider.name}"
end

leadership_course_identifiers = %w[
npq-early-years-leadership
npq-executive-leadership
npq-headship
npq-senco
npq-senior-leadership
]

Rails.logger.info "Move retained-2 leadership declarations from July 2026 to August 2026 for 2025a cohort"

migrator = OneOff::MigrateDeclarationsBetweenStatements
.new(
from_year: 2026,
from_month: 7,
to_year: 2026,
to_month: 8,
cohort: Cohort.find_by!(identifier: "2025a"),
override_date_checks: true,
restrict_to_course_identifiers: leadership_course_identifiers,
restrict_to_declaration_types: "retained-2",
from_statement_updates: { output_fee: false },
to_statement_updates: { output_fee: true },
)

unless migrator.migrate(dry_run:)
Rails.logger.info "Validation failure:"
Rails.logger.info migrator.errors.full_messages.to_yaml
end

if dry_run
Rails.logger.info "DRY RUN: rolling back transaction"
raise ActiveRecord::Rollback
end
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/tasks/one_off/sandbox_test_data_2026_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
expect { run_task }
.to change(Cohort, :count).from(3).to(4)
.and change(Schedule, :count).from(1).to(12)
.and change(Application, :count).from(0).to(78)
.and change(User, :count).from(0).to(78)
.and change(Application, :count).from(0).to(69)
.and change(User, :count).from(0).to(69)
end
end
end
24 changes: 24 additions & 0 deletions spec/models/lead_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
it { is_expected.to validate_uniqueness_of(:ecf_id).case_insensitive.with_message("ECF ID must be unique").allow_nil }
end

describe "scopes" do
describe ".alphabetical" do
subject { described_class.alphabetical }

it "returns lead providers in name alphabetical order" do
expect(subject).to eq LeadProvider.order(name: :asc)
end
end

describe ".active" do
subject { described_class.active }

before do
create(:lead_provider, name: "Education Development Trust", ecf_id: "21e61f53-9b34-4384-a8f5-d8224dbf946d")
create(:lead_provider, name: "School-Led Network", ecf_id: "bc5e4e37-1d64-4149-a06b-ad10d3c55fd0")
create(:lead_provider, name: "Teacher Development Trust", ecf_id: "30fd937e-b93c-4f81-8fff-3c27544193f1")
end

it "returns lead providers in ALL_ACTIVE_PROVIDERS" do
expect(subject).to eq LeadProvider.where(ecf_id: LeadProvider::ALL_ACTIVE_PROVIDERS.values)
end
end
end

describe "#for" do
subject { described_class.for(course:, cohort:).map(&:name) }

Expand Down
Loading