From 53b94e0017836cb8bd7af3174477c1ab02d6ba04 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 27 Jun 2017 17:00:31 +0200 Subject: [PATCH 1/6] Remove tests that test nothing --- spec/models/procedure_spec.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 69f15588a..02ad13cd0 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -247,16 +247,8 @@ describe Procedure do procedure.reload end - it 'is not available from a valid path anymore' do - expect(procedure.path).to eq procedure_path.path - expect(procedure.published).to be_truthy - expect(procedure.archived).to be_truthy - end - - it 'is not in ProcedurePath table anymore' do - expect(ProcedurePath.where(path: procedure.path).count).to eq(1) - expect(ProcedurePath.find_by_procedure_id(procedure.id)).not_to be_nil - end + it { expect(procedure.published).to be_truthy } + it { expect(procedure.archived).to be_truthy } end describe 'total_dossier' do From 28f2ec1d860483b0231eaee0fcd00c50bb9a0d59 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 29 Jun 2017 12:20:27 +0200 Subject: [PATCH 2/6] Reorder some tests --- .../auto_archive_procedure_worker_spec.rb | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/spec/workers/auto_archive_procedure_worker_spec.rb b/spec/workers/auto_archive_procedure_worker_spec.rb index 6e0743477..4fb891ded 100644 --- a/spec/workers/auto_archive_procedure_worker_spec.rb +++ b/spec/workers/auto_archive_procedure_worker_spec.rb @@ -18,43 +18,35 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do end context "when procedures have auto_archive_on set on yesterday or today" do - describe "titi" do - before do - subject - procedure_hier.reload - procedure_aujourdhui.reload - end + let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)} + let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', archived: false)} + let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)} + let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: 'updated', archived: false)} + let!(:dossier5) { create(:dossier, procedure: procedure_hier, state: 'received', archived: false)} + let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'closed', archived: false)} + let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refused', archived: false)} + let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'without_continuation', archived: false)} - it { expect(procedure_hier.archived).to eq true } - it { expect(procedure_aujourdhui.archived).to eq true } + before do + subject + (1..8).each do |i| + eval "dossier#{i}.reload" + end + procedure_hier.reload + procedure_aujourdhui.reload end - context "with dossiers" do - let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)} - let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', archived: false)} - let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)} - let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: 'updated', archived: false)} - let!(:dossier5) { create(:dossier, procedure: procedure_hier, state: 'received', archived: false)} - let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'closed', archived: false)} - let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refused', archived: false)} - let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'without_continuation', archived: false)} + it { expect(dossier1.state).to eq 'draft' } + it { expect(dossier2.state).to eq 'received' } + it { expect(dossier3.state).to eq 'received' } + it { expect(dossier4.state).to eq 'received' } + it { expect(dossier5.state).to eq 'received' } + it { expect(dossier6.state).to eq 'closed' } + it { expect(dossier7.state).to eq 'refused' } + it { expect(dossier8.state).to eq 'without_continuation' } - before do - subject - (1..8).each do |i| - eval "dossier#{i}.reload" - end - end - - it { expect(dossier1.state).to eq 'draft' } - it { expect(dossier2.state).to eq 'received' } - it { expect(dossier3.state).to eq 'received' } - it { expect(dossier4.state).to eq 'received' } - it { expect(dossier5.state).to eq 'received' } - it { expect(dossier6.state).to eq 'closed' } - it { expect(dossier7.state).to eq 'refused' } - it { expect(dossier8.state).to eq 'without_continuation' } - end + it { expect(procedure_hier.archived).to eq true } + it { expect(procedure_aujourdhui.archived).to eq true } end context "when procedures have auto_archive_on set on future" do From 0ec3855f8da76cf6d005bfc8ade7ac04d27a9376 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 29 Jun 2017 15:07:33 +0200 Subject: [PATCH 3/6] Add a missing test --- spec/workers/auto_archive_procedure_worker_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/workers/auto_archive_procedure_worker_spec.rb b/spec/workers/auto_archive_procedure_worker_spec.rb index 4fb891ded..7a9c2a380 100644 --- a/spec/workers/auto_archive_procedure_worker_spec.rb +++ b/spec/workers/auto_archive_procedure_worker_spec.rb @@ -26,12 +26,15 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'closed', archived: false)} let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refused', archived: false)} let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'without_continuation', archived: false)} + let!(:dossier9) { create(:dossier, procedure: procedure_aujourdhui, state: 'initiated', archived: false)} before do subject - (1..8).each do |i| + + (1..9).each do |i| eval "dossier#{i}.reload" end + procedure_hier.reload procedure_aujourdhui.reload end @@ -44,6 +47,7 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do it { expect(dossier6.state).to eq 'closed' } it { expect(dossier7.state).to eq 'refused' } it { expect(dossier8.state).to eq 'without_continuation' } + it { expect(dossier9.state).to eq 'received' } it { expect(procedure_hier.archived).to eq true } it { expect(procedure_aujourdhui.archived).to eq true } From cf573a1ec6df27ca3566ae6225f1fed8a14fc722 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 27 Jun 2017 16:57:25 +0200 Subject: [PATCH 4/6] Use Procedure#archive instead of duplicating code --- app/workers/auto_archive_procedure_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 54875a961..a1a46efcc 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -7,7 +7,7 @@ class AutoArchiveProcedureWorker dossier.received! end - procedure.update_attributes!(archived: true) + procedure.archive end end end From 698bffd1562b08be2f85dbaa10354487a7ffffae Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 27 Jun 2017 16:49:52 +0200 Subject: [PATCH 5/6] [Ref #145] Add the AddArchivedAtToProcedures --- db/migrate/20170627143701_add_archived_at_to_procedure.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170627143701_add_archived_at_to_procedure.rb diff --git a/db/migrate/20170627143701_add_archived_at_to_procedure.rb b/db/migrate/20170627143701_add_archived_at_to_procedure.rb new file mode 100644 index 000000000..ba1bf7890 --- /dev/null +++ b/db/migrate/20170627143701_add_archived_at_to_procedure.rb @@ -0,0 +1,5 @@ +class AddArchivedAtToProcedure < ActiveRecord::Migration[5.0] + def change + add_column :procedures, :archived_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index cd1760bc5..ad99eb400 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170627091953) do +ActiveRecord::Schema.define(version: 20170627143701) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -383,6 +383,7 @@ ActiveRecord::Schema.define(version: 20170627091953) do t.boolean "individual_with_siret", default: false t.datetime "auto_archive_on" t.datetime "published_at" + t.datetime "archived_at" end create_table "quartier_prioritaires", force: :cascade do |t| From 6b90e0ccfad8c2fa36e2a601dfe9bf5b3001e93a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 27 Jun 2017 17:05:49 +0200 Subject: [PATCH 6/6] [Ref #145] Record archived_at when archiving a procedure --- app/models/procedure.rb | 2 +- spec/models/procedure_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index f55595eea..8b6481708 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -116,7 +116,7 @@ class Procedure < ActiveRecord::Base end def archive - self.update_attributes!({archived: true}) + self.update_attributes!(archived: true, archived_at: Time.now) end def total_dossier diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 02ad13cd0..9de535d08 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -227,8 +227,8 @@ describe Procedure do let(:procedure) { create(:procedure) } before do - procedure.publish!("example-path") Timecop.freeze(Time.now) + procedure.publish!("example-path") end it { expect(procedure.published).to eq(true) } @@ -243,12 +243,14 @@ describe Procedure do let(:procedure) { create(:procedure, :published) } let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) } before do + Timecop.freeze(Time.now) procedure.archive procedure.reload end it { expect(procedure.published).to be_truthy } it { expect(procedure.archived).to be_truthy } + it { expect(procedure.archived_at).to eq(Time.now) } end describe 'total_dossier' do