Fix tests to rely on aasm states
This commit is contained in:
parent
365bbe931b
commit
7070b0aba0
12 changed files with 44 additions and 51 deletions
|
@ -2,8 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Admin::PiecesJustificativesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:published_at) { nil }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
@ -19,7 +18,7 @@ describe Admin::PiecesJustificativesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
let(:published_at) { Time.now }
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
|
|
|
@ -92,8 +92,8 @@ describe Admin::ProceduresController, type: :controller do
|
|||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:procedure_draft) { create :procedure, administrateur: admin, published_at: nil, archived_at: nil }
|
||||
let(:procedure_published) { create :procedure, administrateur: admin, published_at: Time.now, archived_at: nil }
|
||||
let(:procedure_archived) { create :procedure, administrateur: admin, published_at: nil, archived_at: Time.now }
|
||||
let(:procedure_published) { create :procedure, administrateur: admin, aasm_state: :publiee, published_at: Time.now, archived_at: nil }
|
||||
let(:procedure_archived) { create :procedure, administrateur: admin, aasm_state: :archivee, published_at: nil, archived_at: Time.now }
|
||||
|
||||
subject { delete :destroy, params: { id: procedure.id } }
|
||||
|
||||
|
@ -344,7 +344,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
it 'publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_truthy
|
||||
expect(procedure.path).to eq(procedure_path)
|
||||
expect(response.status).to eq 200
|
||||
expect(response.status).to eq 302
|
||||
expect(flash[:notice]).to have_content 'Procédure publiée'
|
||||
end
|
||||
end
|
||||
|
@ -355,7 +355,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
it 'publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_truthy
|
||||
expect(procedure.path).to eq(procedure_path)
|
||||
expect(response.status).to eq 200
|
||||
expect(response.status).to eq 302
|
||||
expect(flash[:notice]).to have_content 'Procédure publiée'
|
||||
end
|
||||
|
||||
|
@ -432,8 +432,8 @@ describe Admin::ProceduresController, type: :controller do
|
|||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.archivee?).to be_falsey }
|
||||
it { expect(response.status).to eq 200 }
|
||||
it { expect(procedure.publiee?).to be_truthy }
|
||||
it { expect(response.status).to eq 302 }
|
||||
it { expect(flash[:notice]).to have_content 'Procédure publiée' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,8 +9,7 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:published_at) { nil }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
subject { get :show, params: { procedure_id: procedure_id } }
|
||||
|
@ -21,7 +20,6 @@ describe Admin::TypesDeChampController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
let(:published_at) { Time.now }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:published_at) { nil }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, published_at: published_at) }
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
subject { get :show, params: { procedure_id: procedure_id } }
|
||||
|
@ -21,7 +20,6 @@ describe Admin::TypesDeChampPrivateController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
let(:published_at) { Time.now }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ describe NewGestionnaire::ProceduresController, type: :controller do
|
|||
|
||||
context "with procedures assigned" do
|
||||
let(:procedure1) { create(:procedure, :published) }
|
||||
let(:procedure2) { create(:procedure, :published, :archived) }
|
||||
let(:procedure2) { create(:procedure, :archived) }
|
||||
let(:procedure3) { create(:procedure) }
|
||||
|
||||
before do
|
||||
|
|
|
@ -26,7 +26,7 @@ shared_examples 'description_controller_spec' do
|
|||
|
||||
context 'procedure is archived' do
|
||||
render_views
|
||||
let(:archived_at) { Time.now }
|
||||
let(:archived) { true }
|
||||
|
||||
it { expect(response).to have_http_status(:success) }
|
||||
it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) }
|
||||
|
@ -329,7 +329,7 @@ shared_examples 'description_controller_spec' do
|
|||
end
|
||||
|
||||
context 'La procédure est archivée' do
|
||||
let(:archived_at) { Time.now }
|
||||
let(:archived) { true }
|
||||
|
||||
before do
|
||||
post :update, params: { dossier_id: dossier.id }
|
||||
|
|
|
@ -5,10 +5,15 @@ require 'controllers/users/description_controller_shared_example'
|
|||
describe Users::DescriptionController, type: :controller, vcr: { cassette_name: 'controllers_users_description_controller' } do
|
||||
let(:owner_user) { create(:user) }
|
||||
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
|
||||
let(:archived_at) { nil }
|
||||
let(:archived) { false }
|
||||
let(:state) { 'en_construction' }
|
||||
|
||||
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, published_at: Time.now, archived_at: archived_at) }
|
||||
let(:procedure) do
|
||||
if archived
|
||||
create(:procedure, :archived, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true)
|
||||
else
|
||||
create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true)
|
||||
end
|
||||
end
|
||||
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) }
|
||||
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
|
|
@ -159,17 +159,13 @@ describe Users::DossiersController, type: :controller do
|
|||
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) }
|
||||
|
||||
context 'when procedure is archived' do
|
||||
let(:procedure) { create(:procedure, :published, archived_at: Time.now) }
|
||||
|
||||
before do
|
||||
procedure.update_column :archived_at, Time.now
|
||||
end
|
||||
let(:procedure) { create(:procedure, :archived) }
|
||||
|
||||
it { expect(subject.status).to eq 200 }
|
||||
end
|
||||
|
||||
context 'when procedure is hidden' do
|
||||
let(:procedure) { create(:procedure, :published, hidden_at: DateTime.now) }
|
||||
let(:procedure) { create(:procedure, :hidden) }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AutoArchiveProcedureJob, type: :job do
|
||||
let!(:procedure) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: nil) }
|
||||
let!(:procedure_hier) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: 1.day.ago) }
|
||||
let!(:procedure_aujourdhui) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: Date.today) }
|
||||
let!(:procedure_demain) { create(:procedure, published_at: Time.now, archived_at: nil, auto_archive_on: 1.day.from_now) }
|
||||
let!(:procedure) { create(:procedure, :published, auto_archive_on: nil) }
|
||||
let!(:procedure_hier) { create(:procedure, :published, auto_archive_on: 1.day.ago) }
|
||||
let!(:procedure_aujourdhui) { create(:procedure, :published, auto_archive_on: Date.today) }
|
||||
let!(:procedure_demain) { create(:procedure, :published, auto_archive_on: 1.day.from_now) }
|
||||
|
||||
subject { AutoArchiveProcedureJob.new.perform }
|
||||
|
||||
|
|
|
@ -213,17 +213,17 @@ describe Procedure do
|
|||
end
|
||||
|
||||
describe 'locked?' do
|
||||
let(:procedure) { create(:procedure, published_at: published_at) }
|
||||
let(:procedure) { create(:procedure, aasm_state: aasm_state) }
|
||||
|
||||
subject { procedure.locked? }
|
||||
|
||||
context 'when procedure is in draft status' do
|
||||
let(:published_at) { nil }
|
||||
context 'when procedure is in brouillon status' do
|
||||
let(:aasm_state) { :brouillon }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
context 'when procedure is in draft status' do
|
||||
let(:published_at) { Time.now }
|
||||
context 'when procedure is in publiee status' do
|
||||
let(:aasm_state) { :publiee }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
|
@ -379,8 +379,8 @@ describe Procedure do
|
|||
|
||||
describe "#brouillon?" do
|
||||
let(:procedure_brouillon) { Procedure.new() }
|
||||
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
||||
let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) }
|
||||
|
||||
it { expect(procedure_brouillon.brouillon?).to be_truthy }
|
||||
it { expect(procedure_publiee.brouillon?).to be_falsey }
|
||||
|
@ -389,8 +389,8 @@ describe Procedure do
|
|||
|
||||
describe "#publiee?" do
|
||||
let(:procedure_brouillon) { Procedure.new() }
|
||||
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
||||
let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) }
|
||||
|
||||
it { expect(procedure_brouillon.publiee?).to be_falsey }
|
||||
it { expect(procedure_publiee.publiee?).to be_truthy }
|
||||
|
@ -399,20 +399,18 @@ describe Procedure do
|
|||
|
||||
describe "#archivee?" do
|
||||
let(:procedure_brouillon) { Procedure.new() }
|
||||
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
||||
let(:procedure_batarde) { Procedure.new(published_at: nil, archived_at: Time.now) }
|
||||
let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) }
|
||||
|
||||
it { expect(procedure_brouillon.archivee?).to be_falsey }
|
||||
it { expect(procedure_publiee.archivee?).to be_falsey }
|
||||
it { expect(procedure_archivee.archivee?).to be_truthy }
|
||||
it { expect(procedure_batarde.archivee?).to be_falsey }
|
||||
end
|
||||
|
||||
describe "#publiee_ou_archivee?" do
|
||||
let(:procedure_brouillon) { Procedure.new() }
|
||||
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
||||
let(:procedure_publiee) { Procedure.new(aasm_state: :publiee, published_at: Time.now) }
|
||||
let(:procedure_archivee) { Procedure.new(aasm_state: :archivee, published_at: Time.now, archived_at: Time.now) }
|
||||
|
||||
it { expect(procedure_brouillon.publiee_ou_archivee?).to be_falsey }
|
||||
it { expect(procedure_publiee.publiee_ou_archivee?).to be_truthy }
|
||||
|
@ -425,7 +423,7 @@ describe Procedure do
|
|||
let(:now) { Time.now.beginning_of_minute }
|
||||
before do
|
||||
Timecop.freeze(now)
|
||||
procedure.archive
|
||||
procedure.archive!
|
||||
procedure.reload
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/_closed_mail_template_attestation_inconsistency_alert.html.haml', type: :view do
|
||||
let(:procedure) { create(:procedure, closed_mail: closed_mail, published_at: published_at) }
|
||||
let(:published_at) { nil }
|
||||
let(:procedure) { create(:procedure, closed_mail: closed_mail) }
|
||||
|
||||
def alert
|
||||
assign(:procedure, procedure)
|
||||
|
@ -32,7 +31,7 @@ describe 'admin/_closed_mail_template_attestation_inconsistency_alert.html.haml'
|
|||
it { expect(alert).to include(edit_admin_procedure_mail_template_path(procedure, Mails::ClosedMail::SLUG)) }
|
||||
|
||||
context 'when the procedure has been published, the attestation cannot be deactivated' do
|
||||
let(:published_at) { Time.now }
|
||||
let(:procedure) { create(:procedure, :published, closed_mail: closed_mail) }
|
||||
|
||||
it { expect(procedure.locked?).to be_truthy }
|
||||
it { expect(alert).not_to include(edit_admin_procedure_attestation_template_path(procedure)) }
|
||||
|
|
|
@ -61,7 +61,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
|
|||
describe 'procedure is archived' do
|
||||
before do
|
||||
procedure.publish!('fake_path')
|
||||
procedure.archive
|
||||
procedure.archive!
|
||||
procedure.reload
|
||||
render
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue