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,18 +18,6 @@ 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
|
|
||||||
before do
|
|
||||||
subject
|
|
||||||
procedure_hier.reload
|
|
||||||
procedure_aujourdhui.reload
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect(procedure_hier.archived).to eq true }
|
|
||||||
it { expect(procedure_aujourdhui.archived).to eq true }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with dossiers" do
|
|
||||||
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)}
|
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)}
|
||||||
let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', 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!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)}
|
||||||
|
@ -38,12 +26,17 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
|
||||||
let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'closed', 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!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refused', archived: false)}
|
||||||
let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'without_continuation', 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
|
before do
|
||||||
subject
|
subject
|
||||||
(1..8).each do |i|
|
|
||||||
|
(1..9).each do |i|
|
||||||
eval "dossier#{i}.reload"
|
eval "dossier#{i}.reload"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
procedure_hier.reload
|
||||||
|
procedure_aujourdhui.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(dossier1.state).to eq 'draft' }
|
it { expect(dossier1.state).to eq 'draft' }
|
||||||
|
@ -54,7 +47,10 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
|
||||||
it { expect(dossier6.state).to eq 'closed' }
|
it { expect(dossier6.state).to eq 'closed' }
|
||||||
it { expect(dossier7.state).to eq 'refused' }
|
it { expect(dossier7.state).to eq 'refused' }
|
||||||
it { expect(dossier8.state).to eq 'without_continuation' }
|
it { expect(dossier8.state).to eq 'without_continuation' }
|
||||||
end
|
it { expect(dossier9.state).to eq 'received' }
|
||||||
|
|
||||||
|
it { expect(procedure_hier.archived).to eq true }
|
||||||
|
it { expect(procedure_aujourdhui.archived).to eq true }
|
||||||
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