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

[2315] Bug - Decline by default at date set incorrectly in application #9872

Closed
wants to merge 3 commits into from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module DataMigrations
class SetDeclineByDefaultAtAndDeclineByDefaultDaysToNil
TIMESTAMP = 20240925092609
MANUAL_RUN = true

def change
application_choices.in_batches(of: 4000) do |batch|
batch.update_all(decline_by_default_at: nil, decline_by_default_days: nil)
end
end

private

def application_choices
choices_from_2024
.where.not(decline_by_default_at: nil)
.or(choices_from_2024.where.not(decline_by_default_days: nil))
.distinct
end

def choices_from_2024
@choices_from_2024 ||= ApplicationChoice
.joins(:application_form)
.where('application_form.recruitment_cycle_year': 2024)
.distinct
end
end
end
3 changes: 1 addition & 2 deletions lib/tasks/data.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DATA_MIGRATION_SERVICES = [
# do not delete or edit this line - services added below by generator
'DataMigrations::SetDeclineByDefaultAtAndDeclineByDefaultDaysToNil',
'DataMigrations::BackfillApplicationChoicesWithWorkExperiences',
'DataMigrations::MarkUnsubmittedApplicationsWithoutEnglishProficiencyAsElfIncomplete',
'DataMigrations::BackfillEnglishProficiencyRecordsForCarriedOverApplications',
Expand All @@ -19,8 +20,6 @@ DATA_MIGRATION_SERVICES = [
'DataMigrations::RemoveFeedbackHelpfulFeatureFlag',
'DataMigrations::RemoveOnePersonalStatementFeatureFlag',
'DataMigrations::SetMissingWorkHistoryStatusValues',
'DataMigrations::UpdateDeclineByDefaultAtFromCurrentCycle',
'DataMigrations::RemoveDbdFromCurrentCycle',
'DataMigrations::RemoveRecruitWithPendingConditionsFeatureFlag',
'DataMigrations::BackfillFeedbackFormComplete',
'DataMigrations::RemoveMidCycleReportFeatureFlag',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rails_helper'

RSpec.describe DataMigrations::SetDeclineByDefaultAtAndDeclineByDefaultDaysToNil do
it 'updates choices where decline_by_default_at is not null' do
application_choice = create(:application_choice,
decline_by_default_at: DateTime.now,
decline_by_default_days: nil,
application_form: build(:application_form, recruitment_cycle_year: 2024))

described_class.new.change
expect(application_choice.reload.decline_by_default_at).to be_nil
end

it 'updates choices where decline_by_default_days is not null' do
application_choice = create(:application_choice,
decline_by_default_at: nil,
decline_by_default_days: 10,
application_form: build(:application_form, recruitment_cycle_year: 2024))

described_class.new.change

expect(application_choice.reload.decline_by_default_days).to be_nil
end

it 'updates choices where both days and at are not null' do
application_choice = create(:application_choice,
decline_by_default_at: DateTime.now,
decline_by_default_days: 10,
application_form: build(:application_form, recruitment_cycle_year: 2024))

described_class.new.change

application_choice.reload
expect(application_choice.decline_by_default_days).to be_nil
expect(application_choice.decline_by_default_at).to be_nil
end

it 'updates only 2024 application choices' do
application_2024 = create(:application_choice, decline_by_default_at: Time.zone.now,
application_form: build(:application_form, recruitment_cycle_year: 2024))
application_2023 = create(:application_choice, decline_by_default_at: Time.zone.now,
application_form: build(:application_form, recruitment_cycle_year: 2023))

described_class.new.change

expect(application_2024.reload.decline_by_default_at).to be_nil
expect(application_2023.reload.decline_by_default_at).not_to be_nil
end
end
Loading