diff --git a/app/jobs/tmp_dossiers_migrate_revisions_job.rb b/app/jobs/tmp_dossiers_migrate_revisions_job.rb index 3d5bae95f..1e0669217 100644 --- a/app/jobs/tmp_dossiers_migrate_revisions_job.rb +++ b/app/jobs/tmp_dossiers_migrate_revisions_job.rb @@ -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 diff --git a/spec/jobs/tmp_dossiers_migrate_revisions_job_spec.rb b/spec/jobs/tmp_dossiers_migrate_revisions_job_spec.rb new file mode 100644 index 000000000..ce2984175 --- /dev/null +++ b/spec/jobs/tmp_dossiers_migrate_revisions_job_spec.rb @@ -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