Skip to content

Commit e0d47e4

Browse files
committed
Refactor: Move vacancy backfilling to Vacancy
Since is internal Vacancy logic with no other dependencies or complexity, it seems appropriate to tell "Vacancy" to backfill their missing values.
1 parent f6275bf commit e0d47e4

File tree

7 files changed

+65
-77
lines changed

7 files changed

+65
-77
lines changed

app/models/vacancy.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,19 @@ def contact_email_belongs_to_a_publisher?
297297
Publisher.find_by(email: contact_email).present?
298298
end
299299

300+
def self.backfill_missing_geolocations
301+
where(geolocation: nil).find_each do |v|
302+
v.send(:refresh_geolocation)
303+
v.save!(touch: false, validate: false)
304+
end
305+
end
306+
307+
def self.backfill_missing_searchable_content
308+
where(searchable_content: nil).find_each do |v|
309+
v.save!(touch: false, validate: false)
310+
end
311+
end
312+
300313
private
301314

302315
def update_conversation_searchable_content

app/services/backfills/vacancy_geolocation.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/services/backfills/vacancy_searchable_content.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/tasks/data.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ end
6969
namespace :backfills do
7070
desc "Backfill vacancy geolocation"
7171
task vacancy_geolocation: :environment do
72-
Backfills::VacancyGeolocation.call
72+
Vacancy.backfill_missing_geolocations
7373
end
7474

7575
desc "Backfill vacancy searchable content"
7676
task vacancy_searchable_content: :environment do
77-
Backfills::VacancySearchableContent.call
77+
Vacancy.backfill_missing_searchable_content
7878
end
7979
end
8080

spec/models/vacancy_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,54 @@
892892
end
893893
end
894894
end
895+
896+
describe ".backfill_missing_geolocations" do
897+
context "when there are vacancies without geolocation" do
898+
let!(:vacancy) { create(:vacancy) }
899+
let!(:another_vacancy) { create(:vacancy) }
900+
901+
before do
902+
vacancy.update_column(:geolocation, nil)
903+
another_vacancy.update_column(:geolocation, nil)
904+
end
905+
906+
it "populates geolocation for vacancies missing it" do
907+
expect { described_class.backfill_missing_geolocations }.to change { vacancy.reload.geolocation }.from(nil)
908+
.and change { another_vacancy.reload.geolocation }.from(nil)
909+
end
910+
end
911+
912+
context "when a vacancy already has a geolocation" do
913+
let!(:vacancy) { create(:vacancy) }
914+
915+
it "does not modify it" do
916+
expect { described_class.backfill_missing_geolocations }.not_to(change { vacancy.reload.geolocation })
917+
end
918+
end
919+
end
920+
921+
describe ".backfill_missing_searchable_content" do
922+
context "when there are vacancies without searchable_content" do
923+
let!(:vacancy) { create(:vacancy) }
924+
let!(:another_vacancy) { create(:vacancy) }
925+
926+
before do
927+
vacancy.update_column(:searchable_content, nil)
928+
another_vacancy.update_column(:searchable_content, nil)
929+
end
930+
931+
it "populates searchable_content for vacancies missing it" do
932+
expect { described_class.backfill_missing_searchable_content }.to change { vacancy.reload.searchable_content }.from(nil)
933+
.and change { another_vacancy.reload.searchable_content }.from(nil)
934+
end
935+
end
936+
937+
context "when a vacancy already has searchable_content" do
938+
let!(:vacancy) { create(:vacancy) }
939+
940+
it "does not change it" do
941+
expect { described_class.backfill_missing_searchable_content }.not_to(change { vacancy.reload.searchable_content })
942+
end
943+
end
944+
end
895945
end

spec/services/backfills/vacancy_geolocation_spec.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

spec/services/backfills/vacancy_searchable_content_spec.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)