Skip to content
Draft
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
12 changes: 12 additions & 0 deletions app/models/job_preferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ def to_multistep
def key_stages_for_phases
phases.map { |phase| Vacancy::PHASES_TO_KEY_STAGES_MAPPINGS[phase.to_sym] }.flatten.uniq.sort
end

def self.migrate_legacy_working_patterns
where.not(working_patterns: nil).find_each do |jp|
if jp.working_patterns.include?("term_time")
jp.assign_attributes(working_patterns: (jp.working_patterns - %w[term_time] + %w[full_time]).uniq)
end
if jp.working_patterns.include?("flexible")
jp.assign_attributes(working_patterns: (jp.working_patterns - %w[flexible] + %w[part_time]).uniq)
end
jp.save!(validate: false, touch: false)
end
end
end
7 changes: 7 additions & 0 deletions app/models/published_vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def find_publisher_by_contact_email
.find_by(email: contact_email)
end

def self.discard_out_of_scope
kept.joins(:organisations)
.where(organisations: { detailed_school_type: Organisation::OUT_OF_SCOPE_DETAILED_SCHOOL_TYPES })
.distinct
.find_each(&:trash!)
end

private

def remove_google_index
Expand Down
4 changes: 4 additions & 0 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def set_location_data!
save!
end

def self.discard_invalid
find_each.reject(&:valid?).each(&:discard!)
end

private

# A subscription with location area has a polygon area seat buffered by radius, no geopoint.
Expand Down
13 changes: 13 additions & 0 deletions app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ def contact_email_belongs_to_a_publisher?
Publisher.find_by(email: contact_email).present?
end

def self.backfill_missing_geolocations
where(geolocation: nil).find_each do |v|
v.send(:refresh_geolocation)
v.save!(touch: false, validate: false)
end
end

def self.backfill_missing_searchable_content
where(searchable_content: nil).find_each do |v|
v.save!(touch: false, validate: false)
end
end

private

def update_conversation_searchable_content
Expand Down
7 changes: 0 additions & 7 deletions lib/tasks/backfill_vacancy_geolocation.rake

This file was deleted.

6 changes: 0 additions & 6 deletions lib/tasks/backfill_vacancy_searchable_content.rake

This file was deleted.

33 changes: 33 additions & 0 deletions lib/tasks/data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,39 @@ namespace :ons do
end
end

namespace :backfills do
desc "Backfill vacancy geolocation"
task vacancy_geolocation: :environment do
Vacancy.backfill_missing_geolocations
end

desc "Backfill vacancy searchable content"
task vacancy_searchable_content: :environment do
Vacancy.backfill_missing_searchable_content
end
end

namespace :job_preferences do
desc "Migrate legacy working patterns"
task migrate_legacy_working_patterns: :environment do
JobPreferences.migrate_legacy_working_patterns
end
end

namespace :subscriptions do
desc "Discard subscriptions that fail validation (probably due to invalid email address)"
task discard_invalid: :environment do
Subscription.discard_invalid
end
end

namespace :vacancies do
desc "Trash published vacancies from out-of-scope schools"
task discard_out_of_scope: :environment do
PublishedVacancy.discard_out_of_scope
end
end

namespace :publishers do
desc "Reset 'New features' attributes so all publishers are shown 'New features' page"
task reset_new_features_attributes: :environment do
Expand Down
5 changes: 0 additions & 5 deletions lib/tasks/discard_invalid_subscriptions.rake

This file was deleted.

13 changes: 0 additions & 13 deletions lib/tasks/discard_out_of_scope_vacancies.rake

This file was deleted.

12 changes: 0 additions & 12 deletions lib/tasks/migrate_legacy_job_preferences.rake

This file was deleted.

23 changes: 0 additions & 23 deletions spec/lib/tasks/backfill_vacancy_geolocation_task_spec.rb

This file was deleted.

23 changes: 0 additions & 23 deletions spec/lib/tasks/backfill_vacancy_searchable_content_task_spec.rb

This file was deleted.

18 changes: 0 additions & 18 deletions spec/lib/tasks/discard_invalid_subscriptions_rake_task_spec.rb

This file was deleted.

30 changes: 0 additions & 30 deletions spec/lib/tasks/discard_out_of_scope_vacancies_rake_task_spec.rb

This file was deleted.

29 changes: 0 additions & 29 deletions spec/lib/tasks/migrate_legacy_job_preferences_task_spec.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/models/job_preferences_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,28 @@
end
end
end

describe ".migrate_legacy_working_patterns" do
let!(:pref_a) { create(:job_preferences, working_patterns: %w[term_time flexible part_time]) }
let!(:pref_b) { create(:job_preferences, working_patterns: %w[flexible full_time]) }
let!(:pref_c) { create(:job_preferences, working_patterns: %w[term_time]) }

before do
create(:job_preferences)
create(:job_preferences, working_patterns: nil)
described_class.migrate_legacy_working_patterns
end

it "fixes up term time flexible" do
expect(pref_a.reload.working_patterns).to match_array(%w[full_time part_time])
end

it "fixes up flexible full_time" do
expect(pref_b.reload.working_patterns).to match_array(%w[part_time full_time])
end

it "fixes up term_time" do
expect(pref_c.reload.working_patterns).to match_array(%w[full_time])
end
end
end
26 changes: 26 additions & 0 deletions spec/models/published_vacancy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

RSpec.describe PublishedVacancy do
describe ".discard_out_of_scope" do
it "trashes vacancies from out-of-scope schools" do
in_scope_school = create(:school, detailed_school_type: "Academy sponsor led")
in_scope_vacancy = create(:vacancy, organisations: [in_scope_school])
out_of_scope_school = create(:school, detailed_school_type: "Other independent school")
further_education_school = create(:school, detailed_school_type: "Further education")
higher_education_school = create(:school, detailed_school_type: "Higher education institutions")

out_of_scope_vacancy = create(:vacancy, organisations: [out_of_scope_school])
further_ed_vacancy = create(:vacancy, organisations: [further_education_school])
higher_ed_vacancy = create(:vacancy, organisations: [higher_education_school])

expect {
described_class.discard_out_of_scope
}.to change { described_class.kept.count }.by(-3)

expect(out_of_scope_vacancy.reload).to be_discarded
expect(further_ed_vacancy.reload).to be_discarded
expect(higher_ed_vacancy.reload).to be_discarded
expect(in_scope_vacancy.reload).not_to be_discarded
end
end
end
13 changes: 13 additions & 0 deletions spec/models/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,17 @@
end
end
end

describe ".discard_invalid" do
before do
create(:subscription)
build(:subscription, email: "invalid").save!(validate: false)
end

it "marks the invalid subscription as discarded" do
expect {
described_class.discard_invalid
}.to change { Subscription.kept.count }.by(-1)
end
end
end
Loading
Loading