Merge pull request #5413 from tchak/fix-revision-migration-job

fix active_revision_id -> active_revision.id
This commit is contained in:
Paul Chavard 2020-07-23 15:21:46 +02:00 committed by GitHub
commit 2914a5b4f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -8,7 +8,7 @@ class TmpDossiersMigrateRevisionsJob < ApplicationJob
.limit(2000)
.find_each do |dossier|
if dossier.procedure.present?
dossier.update_column(:revision_id, dossier.procedure.active_revision_id)
dossier.update_column(:revision_id, dossier.procedure.active_revision.id)
else
except << dossier.id
end

View file

@ -0,0 +1,24 @@
RSpec.describe TmpDossiersMigrateRevisionsJob, type: :job do
let(:procedure) { create(:procedure, :published) }
let!(:dossier1) { create(:dossier, procedure: procedure, updated_at: 1.day.ago) }
let!(:dossier2) { create(:dossier, procedure: procedure, updated_at: 2.days.ago) }
context "add revision to dossiers" do
before do
RevisionsMigration.add_revisions(procedure)
end
it {
expect(dossier1.revision).to be_nil
expect(dossier2.revision).to be_nil
TmpDossiersMigrateRevisionsJob.new.perform([])
[dossier1, dossier2].each(&:reload)
expect(dossier1.revision).to eq procedure.active_revision
expect(dossier2.revision).to eq procedure.active_revision
expect(dossier1.updated_at < 1.day.ago).to be_truthy
expect(dossier2.updated_at < 1.day.ago).to be_truthy
}
end
end