Merge pull request #581 from sgmap/procedure-timestamps

Procedure timestamps
This commit is contained in:
gregoirenovel 2017-07-12 10:22:46 +02:00 committed by GitHub
commit 7c3b9ecfa9
21 changed files with 101 additions and 92 deletions

View file

@ -191,7 +191,7 @@ class Admin::ProceduresController < AdminController
render json: ProcedurePath render json: ProcedurePath
.joins(', procedures') .joins(', procedures')
.where("procedures.id = procedure_paths.procedure_id") .where("procedures.id = procedure_paths.procedure_id")
.where("procedures.archived" => false) .where("procedures.archived_at" => nil)
.where("path LIKE '%#{params[:request]}%'") .where("path LIKE '%#{params[:request]}%'")
.pluck(:path, :administrateur_id) .pluck(:path, :administrateur_id)
.inject([]) { .inject([]) {

View file

@ -285,7 +285,7 @@ class Dossier < ActiveRecord::Base
end end
def can_be_initiated? def can_be_initiated?
!(procedure.archived && draft?) !(procedure.archived? && draft?)
end end
def text_summary def text_summary

View file

@ -32,10 +32,10 @@ class Procedure < ActiveRecord::Base
mount_uploader :logo, ProcedureLogoUploader mount_uploader :logo, ProcedureLogoUploader
default_scope { where(hidden_at: nil) } default_scope { where(hidden_at: nil) }
scope :published, -> { where(published: true) } scope :published, -> { where.not(published_at: nil) }
scope :not_published, -> { where(published: false) } scope :not_published, -> { where(published_at: nil) }
scope :archived, -> { where(archived: true) } scope :archived, -> { where.not(archived_at: nil) }
scope :not_archived, -> { where(archived: false) } scope :not_archived, -> { where(archived_at: nil) }
scope :by_libelle, -> { order(libelle: :asc) } scope :by_libelle, -> { order(libelle: :asc) }
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false
@ -106,8 +106,8 @@ class Procedure < ActiveRecord::Base
types_de_champ: :drop_down_list, types_de_champ: :drop_down_list,
types_de_champ_private: :drop_down_list types_de_champ_private: :drop_down_list
}) })
procedure.archived = false procedure.archived_at = nil
procedure.published = false procedure.published_at = nil
procedure.logo_secure_token = nil procedure.logo_secure_token = nil
procedure.remote_logo_url = self.logo_url procedure.remote_logo_url = self.logo_url
@ -121,12 +121,22 @@ class Procedure < ActiveRecord::Base
end end
def publish!(path) def publish!(path)
self.update_attributes!({ published: true, archived: false, published_at: Time.now }) self.update_attributes!({ published_at: Time.now, archived_at: nil })
ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur) ProcedurePath.create!(path: path, procedure: self, administrateur: self.administrateur)
end end
# FIXME: remove once the published colummn has been deleted
def published?
published_at.present?
end
def archive def archive
self.update_attributes!(archived: true, archived_at: Time.now) self.update_attributes!(archived_at: Time.now)
end
# FIXME: remove once the archived colummn has been deleted
def archived?
archived_at.present?
end end
def total_dossier def total_dossier

View file

@ -6,7 +6,7 @@ class ProcedureSerializer < ActiveModel::Serializer
:description, :description,
:organisation, :organisation,
:direction, :direction,
:archived, :archived_at,
:geographic_information, :geographic_information,
:total_dossier :total_dossier

View file

@ -152,7 +152,7 @@
"description": "Demande de subvention à l'intention des associations", "description": "Demande de subvention à l'intention des associations",
"organisation": "Orga SGMAP", "organisation": "Orga SGMAP",
"direction": "direction SGMAP", "direction": "direction SGMAP",
"archived": false, "archived_at": null,
"geographic_information": { "geographic_information": {
"use_api_carto": false, "use_api_carto": false,
"quartiers_prioritaires": false, "quartiers_prioritaires": false,

View file

@ -2,8 +2,8 @@ require 'spec_helper'
describe Admin::PiecesJustificativesController, type: :controller do describe Admin::PiecesJustificativesController, type: :controller do
let(:admin) { create(:administrateur) } let(:admin) { create(:administrateur) }
let(:published) { false } let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published: published) } let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
before do before do
sign_in admin sign_in admin
end end
@ -19,7 +19,7 @@ describe Admin::PiecesJustificativesController, type: :controller do
end end
context 'when procedure is published' do context 'when procedure is published' do
let(:published) { true } let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -54,9 +54,9 @@ describe Admin::ProceduresController, type: :controller do
end end
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
let(:procedure_draft) { create :procedure, published: false, archived: false } let(:procedure_draft) { create :procedure, published_at: nil, archived_at: nil }
let(:procedure_published) { create :procedure, published: true, archived: false } let(:procedure_published) { create :procedure, published_at: Time.now, archived_at: nil }
let(:procedure_archived) { create :procedure, published: false, archived: true } let(:procedure_archived) { create :procedure, published_at: nil, archived_at: Time.now }
subject { delete :destroy, params: {id: procedure.id} } subject { delete :destroy, params: {id: procedure.id} }
@ -94,8 +94,8 @@ describe Admin::ProceduresController, type: :controller do
end end
describe 'GET #edit' do describe 'GET #edit' do
let(:published) { false } let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published: published) } let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
subject { get :edit, params: {id: procedure_id} } subject { get :edit, params: {id: procedure_id} }
@ -115,7 +115,7 @@ describe Admin::ProceduresController, type: :controller do
end end
context 'when procedure is published' do context 'when procedure is published' do
let(:published) { true } let(:published_at) { Time.now }
it { is_expected.to have_http_status(:success) } it { is_expected.to have_http_status(:success) }
end end
@ -297,7 +297,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'new_path' } let(:procedure_path) { 'new_path' }
it 'publish the given procedure' do it 'publish the given procedure' do
expect(procedure.published).to be_truthy expect(procedure.published?).to be_truthy
expect(procedure.path).to eq(procedure_path) expect(procedure.path).to eq(procedure_path)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée' expect(flash[:notice]).to have_content 'Procédure publiée'
@ -308,15 +308,15 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { procedure2.path } let(:procedure_path) { procedure2.path }
it 'publish the given procedure' do it 'publish the given procedure' do
expect(procedure.published).to be_truthy expect(procedure.published?).to be_truthy
expect(procedure.path).to eq(procedure_path) expect(procedure.path).to eq(procedure_path)
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(flash[:notice]).to have_content 'Procédure publiée' expect(flash[:notice]).to have_content 'Procédure publiée'
end end
it 'archive previous procedure' do it 'archive previous procedure' do
expect(procedure2.published).to be_truthy expect(procedure2.published?).to be_truthy
expect(procedure2.archived).to be_truthy expect(procedure2.archived?).to be_truthy
expect(procedure2.path).to be_nil expect(procedure2.path).to be_nil
end end
end end
@ -325,14 +325,14 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { procedure3.path } let(:procedure_path) { procedure3.path }
it 'does not publish the given procedure' do it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey expect(procedure.published?).to be_falsey
expect(procedure.path).to be_nil expect(procedure.path).to be_nil
expect(response.status).to eq 200 expect(response.status).to eq 200
end end
it 'previous procedure remains published' do it 'previous procedure remains published' do
expect(procedure2.published).to be_truthy expect(procedure2.published?).to be_truthy
expect(procedure2.archived).to be_falsey expect(procedure2.archived?).to be_falsey
expect(procedure2.path).to match(/fake_path/) expect(procedure2.path).to match(/fake_path/)
end end
end end
@ -341,7 +341,7 @@ describe Admin::ProceduresController, type: :controller do
let(:procedure_path) { 'Invalid Procedure Path' } let(:procedure_path) { 'Invalid Procedure Path' }
it 'does not publish the given procedure' do it 'does not publish the given procedure' do
expect(procedure.published).to be_falsey expect(procedure.published?).to be_falsey
expect(procedure.path).to be_nil expect(procedure.path).to be_nil
expect(response).to redirect_to :admin_procedures expect(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Lien de la procédure invalide' expect(flash[:alert]).to have_content 'Lien de la procédure invalide'
@ -377,7 +377,7 @@ describe Admin::ProceduresController, type: :controller do
end end
context 'when owner want archive procedure' do context 'when owner want archive procedure' do
it { expect(procedure.archived).to be_truthy } it { expect(procedure.archived?).to be_truthy }
it { expect(response).to redirect_to :admin_procedures } it { expect(response).to redirect_to :admin_procedures }
it { expect(flash[:notice]).to have_content 'Procédure archivée' } it { expect(flash[:notice]).to have_content 'Procédure archivée' }
end end
@ -388,7 +388,7 @@ describe Admin::ProceduresController, type: :controller do
procedure.reload procedure.reload
end end
it { expect(procedure.archived).to be_falsey } it { expect(procedure.archived?).to be_falsey }
it { expect(response.status).to eq 200 } it { expect(response.status).to eq 200 }
it { expect(flash[:notice]).to have_content 'Procédure publiée' } it { expect(flash[:notice]).to have_content 'Procédure publiée' }
end end
@ -479,7 +479,7 @@ describe Admin::ProceduresController, type: :controller do
context 'when procedure is archived' do context 'when procedure is archived' do
before do before do
procedure3.update_attribute :archived, true procedure3.update_attribute :archived_at, Time.now
subject subject
end end

View file

@ -9,8 +9,8 @@ describe Admin::TypesDeChampController, type: :controller do
end end
describe 'GET #show' do describe 'GET #show' do
let(:published) { false } let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published: published) } let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
subject { get :show, params: {procedure_id: procedure_id} } subject { get :show, params: {procedure_id: procedure_id} }
@ -21,7 +21,7 @@ describe Admin::TypesDeChampController, type: :controller do
end end
context 'when procedure is published' do context 'when procedure is published' do
let(:published) { true } let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -9,8 +9,8 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
end end
describe 'GET #show' do describe 'GET #show' do
let(:published) { false } let(:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: admin, published: published) } let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
subject { get :show, params: {procedure_id: procedure_id} } subject { get :show, params: {procedure_id: procedure_id} }
@ -21,7 +21,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
end end
context 'when procedure is published' do context 'when procedure is published' do
let(:published) { true } let(:published_at) { Time.now }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id } it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end end

View file

@ -34,7 +34,7 @@ describe API::V1::ProceduresController, type: :controller do
it { expect(subject[:organisation]).to eq(procedure.organisation) } it { expect(subject[:organisation]).to eq(procedure.organisation) }
it { expect(subject[:direction]).to eq(procedure.direction) } it { expect(subject[:direction]).to eq(procedure.direction) }
it { expect(subject[:link]).to eq(procedure.lien_demarche) } it { expect(subject[:link]).to eq(procedure.lien_demarche) }
it { expect(subject[:archived]).to eq(procedure.archived) } it { expect(subject[:archived_at]).to eq(procedure.archived_at) }
it { expect(subject[:total_dossier]).to eq(procedure.total_dossier) } it { expect(subject[:total_dossier]).to eq(procedure.total_dossier) }
it { is_expected.to have_key(:types_de_champ) } it { is_expected.to have_key(:types_de_champ) }
it { expect(subject[:types_de_champ]).to be_an(Array) } it { expect(subject[:types_de_champ]).to be_an(Array) }

View file

@ -118,18 +118,18 @@ describe StatsController, type: :controller do
before do before do
3.times do 3.times do
create(:procedure, published: true, administrateur: administrateur_1) create(:procedure, published_at: Time.now, administrateur: administrateur_1)
end end
2.times do 2.times do
create(:procedure, published: true, administrateur: administrateur_2) create(:procedure, published_at: Time.now, administrateur: administrateur_2)
end end
8.times do 8.times do
create(:procedure, published: true, administrateur: administrateur_3) create(:procedure, published_at: Time.now, administrateur: administrateur_3)
end end
create(:procedure, published: true, administrateur: administrateur_4) create(:procedure, published_at: Time.now, administrateur: administrateur_4)
end end
let(:association){ Procedure.all } let(:association){ Procedure.all }

View file

@ -26,7 +26,7 @@ shared_examples 'description_controller_spec' do
context 'procedure is archived' do context 'procedure is archived' do
render_views render_views
let(:archived) { true } let(:archived_at) { Time.now }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) } it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }
@ -298,7 +298,7 @@ shared_examples 'description_controller_spec' do
end end
context 'La procédure est archivée' do context 'La procédure est archivée' do
let(:archived) { true } let(:archived_at) { Time.now }
before do before do
post :update, params: { dossier_id: dossier.id } post :update, params: { dossier_id: dossier.id }

View file

@ -5,10 +5,10 @@ require 'controllers/users/description_controller_shared_example'
describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do describe Users::DescriptionController, type: :controller, vcr: {cassette_name: 'controllers_users_description_controller'} do
let(:owner_user) { create(:user) } let(:owner_user) { create(:user) }
let(:invite_by_user) { create :user, email: 'invite@plop.com' } let(:invite_by_user) { create :user, email: 'invite@plop.com' }
let(:archived) { false } let(:archived_at) { nil }
let(:state) { 'initiated' } let(:state) { 'initiated' }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived: archived) } let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived_at: archived_at) }
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) } let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }

View file

@ -118,7 +118,7 @@ describe Users::DossiersController, type: :controller do
end end
context 'when procedure is archived' do context 'when procedure is archived' do
let(:procedure) { create(:procedure, archived: 'true') } let(:procedure) { create(:procedure, archived_at: Time.now) }
it { is_expected.to redirect_to users_dossiers_path } it { is_expected.to redirect_to users_dossiers_path }
end end
@ -140,7 +140,7 @@ describe Users::DossiersController, type: :controller do
end end
context 'when procedure is not published' do context 'when procedure is not published' do
let(:procedure) { create(:procedure, published: false) } let(:procedure) { create(:procedure, published_at: nil) }
before do before do
sign_in user sign_in user
@ -158,10 +158,10 @@ describe Users::DossiersController, type: :controller do
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
context 'when procedure is archived' do context 'when procedure is archived' do
let(:procedure) { create(:procedure, :published, archived: true) } let(:procedure) { create(:procedure, :published, archived_at: Time.now) }
before do before do
procedure.update_column :archived, true procedure.update_column :archived_at, Time.now
end end
it { expect(subject.status).to eq 200 } it { expect(subject.status).to eq 200 }

View file

@ -220,7 +220,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure is not published' do context 'when procedure is not published' do
let(:procedure) { create :procedure, published: false } let(:procedure) { create :procedure, published_at: nil }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"
end end
@ -230,7 +230,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when procedure_id exist' do context 'when procedure_id exist' do
let(:procedure) { create :procedure, published: true } let(:procedure) { create :procedure, published_at: Time.now }
before do before do
session["user_return_to"] = "?procedure_id=#{procedure.id}" session["user_return_to"] = "?procedure_id=#{procedure.id}"

View file

@ -6,7 +6,7 @@ FactoryGirl.define do
description "Demande de subvention à l'intention des associations" description "Demande de subvention à l'intention des associations"
organisation "Orga SGMAP" organisation "Orga SGMAP"
direction "direction SGMAP" direction "direction SGMAP"
published false published_at nil
cerfa_flag false cerfa_flag false
administrateur { create(:administrateur) } administrateur { create(:administrateur) }

View file

@ -2,8 +2,8 @@ require 'spec_helper'
feature 'procedure locked' do feature 'procedure locked' do
let(:administrateur) { create(:administrateur) } let(:administrateur) { create(:administrateur) }
let(:published) { false } let (:published_at) { nil }
let(:procedure) { create(:procedure, administrateur: administrateur, published: published) } let(:procedure) { create(:procedure, administrateur: administrateur, published_at: published_at) }
before do before do
login_as administrateur, scope: :administrateur login_as administrateur, scope: :administrateur

View file

@ -370,14 +370,14 @@ describe Gestionnaire, type: :model do
end end
context 'when no procedure published was active last week' do context 'when no procedure published was active last week' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) } let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
context 'when the gestionnaire has no notifications' do context 'when the gestionnaire has no notifications' do
it { is_expected.to eq(nil) } it { is_expected.to eq(nil) }
end end
end end
context 'when a procedure published was active' do context 'when a procedure published was active' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) } let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: Time.now) }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do
@ -388,7 +388,7 @@ describe Gestionnaire, type: :model do
end end
context 'when a procedure not published was active with no notifications' do context 'when a procedure not published was active with no notifications' do
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: false) } let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published_at: nil) }
let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) } let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) }
before :each do before :each do

View file

@ -97,54 +97,54 @@ describe Procedure do
end end
describe 'locked?' do describe 'locked?' do
let(:procedure) { create(:procedure, published: published) } let(:procedure) { create(:procedure, published_at: published_at) }
subject { procedure.locked? } subject { procedure.locked? }
context 'when procedure is in draft status' do context 'when procedure is in draft status' do
let(:published) { false } let(:published_at) { nil }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when procedure is in draft status' do context 'when procedure is in draft status' do
let(:published) { true } let(:published_at) { Time.now }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
end end
describe 'active' do describe 'active' do
let(:procedure) { create(:procedure, published: published, archived: archived) } let(:procedure) { create(:procedure, published_at: published_at, archived_at: archived_at) }
subject { Procedure.active(procedure.id) } subject { Procedure.active(procedure.id) }
context 'when procedure is in draft status and not archived' do context 'when procedure is in draft status and not archived' do
let(:published) { false } let(:published_at) { nil }
let(:archived) { false } let(:archived_at) { nil }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
context 'when procedure is published and not archived' do context 'when procedure is published and not archived' do
let(:published) { true } let(:published_at) { Time.now }
let(:archived) { false } let(:archived_at) { nil }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when procedure is published and archived' do context 'when procedure is published and archived' do
let(:published) { true } let(:published_at) { Time.now }
let(:archived) { true } let(:archived_at) { Time.now }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
context 'when procedure is in draft status and archived' do context 'when procedure is in draft status and archived' do
let(:published) { false } let(:published_at) { nil }
let(:archived) { true } let(:archived_at) { Time.now }
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
end end
end end
describe 'clone' do describe 'clone' do
let(:archived) { false } let(:archived_at) { nil }
let(:published) { false } let(:published_at) { nil }
let(:procedure) { create(:procedure, archived: archived, published: published, received_mail: received_mail) } let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail) }
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) } let!(:type_de_champ_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) }
@ -213,11 +213,11 @@ describe Procedure do
end end
describe 'procedure status is reset' do describe 'procedure status is reset' do
let(:archived) { true } let(:archived_at) { Time.now }
let(:published) { true } let(:published_at) { Time.now }
it 'Not published nor archived' do it 'Not published nor archived' do
expect(subject.archived).to be_falsey expect(subject.archived_at).to be_nil
expect(subject.published).to be_falsey expect(subject.published_at).to be_nil
expect(subject.path).to be_nil expect(subject.path).to be_nil
end end
end end
@ -232,8 +232,7 @@ describe Procedure do
procedure.publish!("example-path") procedure.publish!("example-path")
end end
it { expect(procedure.published).to eq(true) } it { expect(procedure.archived_at).to eq(nil) }
it { expect(procedure.archived).to eq(false) }
it { expect(procedure.published_at).to eq(now) } it { expect(procedure.published_at).to eq(now) }
it { expect(ProcedurePath.find_by_path("example-path")).to be } it { expect(ProcedurePath.find_by_path("example-path")).to be }
it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) } it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) }
@ -254,8 +253,8 @@ describe Procedure do
procedure.reload procedure.reload
end end
it { expect(procedure.published).to be_truthy } it { expect(procedure.published?).to be_truthy }
it { expect(procedure.archived).to be_truthy } it { expect(procedure.archived?).to be_truthy }
it { expect(procedure.archived_at).to eq(now) } it { expect(procedure.archived_at).to eq(now) }
after do after do

View file

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe 'admin/procedures/show.html.haml', type: :view do describe 'admin/procedures/show.html.haml', type: :view do
let(:archived) { false } let(:archived_at) { nil }
let(:procedure) { create(:procedure, archived: archived) } let(:procedure) { create(:procedure, archived_at: archived_at) }
before do before do
assign(:facade, AdminProceduresShowFacades.new(procedure.decorate)) assign(:facade, AdminProceduresShowFacades.new(procedure.decorate))

View file

@ -1,10 +1,10 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe AutoArchiveProcedureWorker, type: :worker do RSpec.describe AutoArchiveProcedureWorker, type: :worker do
let!(:procedure) { create(:procedure, archived: false, auto_archive_on: nil )} let!(:procedure) { create(:procedure, archived_at: nil, auto_archive_on: nil )}
let!(:procedure_hier) { create(:procedure, archived: false, auto_archive_on: 1.day.ago )} let!(:procedure_hier) { create(:procedure, archived_at: nil, auto_archive_on: 1.day.ago )}
let!(:procedure_aujourdhui) { create(:procedure, archived: false, auto_archive_on: Date.today )} let!(:procedure_aujourdhui) { create(:procedure, archived_at: nil, auto_archive_on: Date.today )}
let!(:procedure_demain) { create(:procedure, archived: false, auto_archive_on: 1.day.from_now )} let!(:procedure_demain) { create(:procedure, archived_at: nil, auto_archive_on: 1.day.from_now )}
subject { AutoArchiveProcedureWorker.new.perform } subject { AutoArchiveProcedureWorker.new.perform }
@ -14,7 +14,7 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
procedure.reload procedure.reload
end end
it { expect(procedure.archived).to eq false } it { expect(procedure.archived?).to eq false }
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
@ -49,8 +49,8 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
it { expect(dossier8.state).to eq 'without_continuation' } it { expect(dossier8.state).to eq 'without_continuation' }
it { expect(dossier9.state).to eq 'received' } it { expect(dossier9.state).to eq 'received' }
it { expect(procedure_hier.archived).to eq true } it { expect(procedure_hier.archived?).to eq true }
it { expect(procedure_aujourdhui.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
@ -58,6 +58,6 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do
subject subject
end end
it { expect(procedure_demain.archived).to eq false } it { expect(procedure_demain.archived?).to eq false }
end end
end end