commit
6bd2edf2d3
6 changed files with 42 additions and 46 deletions
|
@ -116,7 +116,7 @@ class Procedure < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
self.update_attributes!({archived: true})
|
self.update_attributes!(archived: true, archived_at: Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_dossier
|
def total_dossier
|
||||||
|
|
|
@ -7,7 +7,7 @@ class AutoArchiveProcedureWorker
|
||||||
dossier.received!
|
dossier.received!
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure.update_attributes!(archived: true)
|
procedure.archive
|
||||||
end
|
end
|
||||||
end
|
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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -383,6 +383,7 @@ ActiveRecord::Schema.define(version: 20170627091953) do
|
||||||
t.boolean "individual_with_siret", default: false
|
t.boolean "individual_with_siret", default: false
|
||||||
t.datetime "auto_archive_on"
|
t.datetime "auto_archive_on"
|
||||||
t.datetime "published_at"
|
t.datetime "published_at"
|
||||||
|
t.datetime "archived_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "quartier_prioritaires", force: :cascade do |t|
|
create_table "quartier_prioritaires", force: :cascade do |t|
|
||||||
|
|
|
@ -227,8 +227,8 @@ describe Procedure do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
procedure.publish!("example-path")
|
|
||||||
Timecop.freeze(Time.now)
|
Timecop.freeze(Time.now)
|
||||||
|
procedure.publish!("example-path")
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(procedure.published).to eq(true) }
|
it { expect(procedure.published).to eq(true) }
|
||||||
|
@ -243,20 +243,14 @@ describe Procedure do
|
||||||
let(:procedure) { create(:procedure, :published) }
|
let(:procedure) { create(:procedure, :published) }
|
||||||
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
|
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
|
||||||
before do
|
before do
|
||||||
|
Timecop.freeze(Time.now)
|
||||||
procedure.archive
|
procedure.archive
|
||||||
procedure.reload
|
procedure.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is not available from a valid path anymore' do
|
it { expect(procedure.published).to be_truthy }
|
||||||
expect(procedure.path).to eq procedure_path.path
|
it { expect(procedure.archived).to be_truthy }
|
||||||
expect(procedure.published).to be_truthy
|
it { expect(procedure.archived_at).to eq(Time.now) }
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'total_dossier' do
|
describe 'total_dossier' do
|
||||||
|
|
|
@ -18,43 +18,39 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when procedures have auto_archive_on set on yesterday or today" do
|
context "when procedures have auto_archive_on set on yesterday or today" do
|
||||||
describe "titi" do
|
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)}
|
||||||
before do
|
let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', archived: false)}
|
||||||
subject
|
let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)}
|
||||||
procedure_hier.reload
|
let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: 'updated', archived: false)}
|
||||||
procedure_aujourdhui.reload
|
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
|
end
|
||||||
|
|
||||||
it { expect(procedure_hier.archived).to eq true }
|
procedure_hier.reload
|
||||||
it { expect(procedure_aujourdhui.archived).to eq true }
|
procedure_aujourdhui.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with dossiers" do
|
it { expect(dossier1.state).to eq 'draft' }
|
||||||
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)}
|
it { expect(dossier2.state).to eq 'received' }
|
||||||
let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', archived: false)}
|
it { expect(dossier3.state).to eq 'received' }
|
||||||
let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)}
|
it { expect(dossier4.state).to eq 'received' }
|
||||||
let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: 'updated', archived: false)}
|
it { expect(dossier5.state).to eq 'received' }
|
||||||
let!(:dossier5) { create(:dossier, procedure: procedure_hier, state: 'received', archived: false)}
|
it { expect(dossier6.state).to eq 'closed' }
|
||||||
let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'closed', archived: false)}
|
it { expect(dossier7.state).to eq 'refused' }
|
||||||
let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refused', archived: false)}
|
it { expect(dossier8.state).to eq 'without_continuation' }
|
||||||
let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'without_continuation', archived: false)}
|
it { expect(dossier9.state).to eq 'received' }
|
||||||
|
|
||||||
before do
|
it { expect(procedure_hier.archived).to eq true }
|
||||||
subject
|
it { expect(procedure_aujourdhui.archived).to eq true }
|
||||||
(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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when procedures have auto_archive_on set on future" do
|
context "when procedures have auto_archive_on set on future" do
|
||||||
|
|
Loading…
Reference in a new issue