commit
6bd2edf2d3
6 changed files with 42 additions and 46 deletions
|
@ -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
|
||||
|
|
|
@ -7,7 +7,7 @@ class AutoArchiveProcedureWorker
|
|||
dossier.received!
|
||||
end
|
||||
|
||||
procedure.update_attributes!(archived: true)
|
||||
procedure.archive
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddArchivedAtToProcedure < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :procedures, :archived_at, :datetime
|
||||
end
|
||||
end
|
|
@ -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|
|
||||
|
|
|
@ -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,20 +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 '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 }
|
||||
it { expect(procedure.archived_at).to eq(Time.now) }
|
||||
end
|
||||
|
||||
describe 'total_dossier' do
|
||||
|
|
|
@ -18,43 +18,39 @@ 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
|
||||
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)}
|
||||
let!(:dossier9) { create(:dossier, procedure: procedure_aujourdhui, state: 'initiated', archived: false)}
|
||||
|
||||
before do
|
||||
subject
|
||||
|
||||
(1..9).each do |i|
|
||||
eval "dossier#{i}.reload"
|
||||
end
|
||||
|
||||
it { expect(procedure_hier.archived).to eq true }
|
||||
it { expect(procedure_aujourdhui.archived).to eq true }
|
||||
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' }
|
||||
it { expect(dossier9.state).to eq 'received' }
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue