Update specs to use multiple administrateurs

This commit is contained in:
Paul Chavard 2019-02-26 16:57:04 +01:00
parent 01b966ff66
commit c37f649453
15 changed files with 33 additions and 26 deletions

View file

@ -38,7 +38,7 @@ class API::V1::DossiersController < APIController
def fetch_procedure_and_check_token def fetch_procedure_and_check_token
@procedure = Procedure.for_api.find(params[:procedure_id]) @procedure = Procedure.for_api.find(params[:procedure_id])
if !valid_token_for_administrateur?(@procedure.administrateurs) if !valid_token_for_procedure?(@procedure)
render json: {}, status: :unauthorized render json: {}, status: :unauthorized
end end

View file

@ -10,7 +10,7 @@ class API::V1::ProceduresController < APIController
def fetch_procedure_and_check_token def fetch_procedure_and_check_token
@procedure = Procedure.for_api.find(params[:id]) @procedure = Procedure.for_api.find(params[:id])
if !valid_token_for_administrateur?(@procedure.administrateurs) if !valid_token_for_procedure?(@procedure)
render json: {}, status: :unauthorized render json: {}, status: :unauthorized
end end

View file

@ -3,8 +3,8 @@ class APIController < ApplicationController
protected protected
def valid_token_for_administrateur?(administrateurs) def valid_token_for_procedure?(procedure)
administrateurs.any? do |administrateur| procedure.administrateurs.any? do |administrateur|
administrateur.valid_api_token?(token) administrateur.valid_api_token?(token)
end end
end end

View file

@ -5,7 +5,7 @@ describe Admin::MailTemplatesController, type: :controller do
let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) } let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) }
before do before do
sign_in procedure.administrateur sign_in procedure.administrateurs.first
end end
describe 'GET index' do describe 'GET index' do

View file

@ -40,7 +40,8 @@ describe Admin::ProceduresController, type: :controller do
describe 'GET #index with sorting and pagination' do describe 'GET #index with sorting and pagination' do
before do before do
admin.procedures << create(:procedure, administrateur: admin) create(:procedure, administrateur: admin)
admin.reload
end end
subject { subject {
@ -196,7 +197,6 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.description).to eq(description) } it { expect(subject.description).to eq(description) }
it { expect(subject.organisation).to eq(organisation) } it { expect(subject.organisation).to eq(organisation) }
it { expect(subject.direction).to eq(direction) } it { expect(subject.direction).to eq(direction) }
it { expect(subject.administrateur_id).to eq(admin.id) }
it { expect(subject.administrateurs).to eq([admin]) } it { expect(subject.administrateurs).to eq([admin]) }
it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) } it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) }
it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) } it { expect(subject.duree_conservation_dossiers_hors_ds).to eq(duree_conservation_dossiers_hors_ds) }
@ -636,7 +636,7 @@ describe Admin::ProceduresController, type: :controller do
subject subject
end end
it { expect(Procedure.last.administrateur).to eq new_admin } it { expect(Procedure.last.administrateurs).to eq [new_admin] }
end end
end end
end end

View file

@ -1,10 +1,11 @@
require 'spec_helper' require 'spec_helper'
describe APIController, type: :controller do describe APIController, type: :controller do
describe 'valid_token_for_administrateur?' do describe 'valid_token_for_procedure?' do
let!(:admin) { create(:administrateur) } let(:procedure) { create(:procedure) }
let(:admin) { procedure.administrateurs.first }
subject { controller.send(:'valid_token_for_administrateur?', admin) } subject { controller.send(:'valid_token_for_procedure?', procedure) }
context 'when the admin has not any token' do context 'when the admin has not any token' do
context 'and the token is not given' do context 'and the token is not given' do

View file

@ -815,7 +815,7 @@ describe NewUser::DossiersController, type: :controller do
let(:dossier) { create(:dossier, :en_construction, user: user, autorisation_donnees: true) } let(:dossier) { create(:dossier, :en_construction, user: user, autorisation_donnees: true) }
it "notifies the user and the admin of the deletion" do it "notifies the user and the admin of the deletion" do
expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateur.email).and_return(double(deliver_later: nil)) expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateurs.first.email).and_return(double(deliver_later: nil))
expect(DossierMailer).to receive(:notify_deletion_to_user).with(kind_of(DeletedDossier), dossier.user.email).and_return(double(deliver_later: nil)) expect(DossierMailer).to receive(:notify_deletion_to_user).with(kind_of(DeletedDossier), dossier.user.email).and_return(double(deliver_later: nil))
subject subject
end end

View file

@ -23,7 +23,8 @@ FactoryBot.define do
trait :with_procedure do trait :with_procedure do
after(:create) do |admin| after(:create) do |admin|
admin.procedures << create(:simple_procedure, administrateur: admin) create(:simple_procedure, administrateur: admin)
admin.reload
end end
end end
end end

View file

@ -7,13 +7,20 @@ FactoryBot.define do
direction { "direction DINSIC" } direction { "direction DINSIC" }
cadre_juridique { "un cadre juridique important" } cadre_juridique { "un cadre juridique important" }
published_at { nil } published_at { nil }
administrateur { create(:administrateur) }
duree_conservation_dossiers_dans_ds { 3 } duree_conservation_dossiers_dans_ds { 3 }
duree_conservation_dossiers_hors_ds { 6 } duree_conservation_dossiers_hors_ds { 6 }
ask_birthday { false } ask_birthday { false }
after(:build) do |procedure| transient do
procedure.administrateurs = [procedure.administrateur] administrateur {}
end
after(:build) do |procedure, evaluator|
if evaluator.administrateur
procedure.administrateurs = [evaluator.administrateur]
elsif procedure.administrateurs.empty?
procedure.administrateurs = [create(:administrateur)]
end
end end
factory :procedure_with_dossiers do factory :procedure_with_dossiers do

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
feature 'As an administrateur I can edit types de champ', js: true do feature 'As an administrateur I can edit types de champ', js: true do
let(:administrateur) { procedure.administrateur } let(:administrateur) { procedure.administrateurs.first }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
before do before do

View file

@ -652,7 +652,7 @@ describe Dossier do
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
it 'notifies the procedure administrateur' do it 'notifies the procedure administrateur' do
expect(DossierMailer).to have_received(:notify_deletion_to_administration).once expect(DossierMailer).to have_received(:notify_deletion_to_administration).once
expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateur.email) expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateurs.first.email)
end end
end end

View file

@ -344,7 +344,7 @@ describe Procedure do
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
let(:received_mail) { create(:received_mail) } let(:received_mail) { create(:received_mail) }
let(:from_library) { false } let(:from_library) { false }
let(:administrateur) { procedure.administrateur } let(:administrateur) { procedure.administrateurs.first }
before do before do
@logo = File.open('spec/fixtures/files/white.png') @logo = File.open('spec/fixtures/files/white.png')
@ -419,7 +419,6 @@ describe Procedure do
end end
it 'should have one administrateur' do it 'should have one administrateur' do
expect(subject.administrateur).to eq(administrateur)
expect(subject.administrateurs).to eq([administrateur]) expect(subject.administrateurs).to eq([administrateur])
end end
end end
@ -444,7 +443,6 @@ describe Procedure do
end end
it 'should have one administrateur' do it 'should have one administrateur' do
expect(subject.administrateur).to eq(administrateur)
expect(subject.administrateurs).to eq([administrateur]) expect(subject.administrateurs).to eq([administrateur])
end end
end end
@ -502,7 +500,7 @@ describe Procedure do
it { expect(procedure.archived_at).to eq(nil) } it { expect(procedure.archived_at).to eq(nil) }
it { expect(procedure.published_at).to eq(now) } it { expect(procedure.published_at).to eq(now) }
it { expect(Procedure.find_by(path: "example-path")).to eq(procedure) } it { expect(Procedure.find_by(path: "example-path")).to eq(procedure) }
it { expect(Procedure.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) } it { expect(Procedure.find_by(path: "example-path").administrateurs).to eq(procedure.administrateurs) }
end end
describe "#brouillon?" do describe "#brouillon?" do

View file

@ -59,7 +59,7 @@ describe DossierSerializer do
end end
let(:procedure) do let(:procedure) do
p = original_procedure.clone(original_procedure.administrateur, false) p = original_procedure.clone(original_procedure.administrateurs.first, false)
p.save p.save
p p
end end

View file

@ -21,7 +21,7 @@ describe ProcedureSerializer do
p p
end end
let(:procedure) { original_procedure.clone(original_procedure.administrateur, false) } let(:procedure) { original_procedure.clone(original_procedure.administrateurs.first, false) }
let(:type_pj) { original_procedure.types_de_piece_justificative.first } let(:type_pj) { original_procedure.types_de_piece_justificative.first }
let(:migrated_type_champ) { procedure.types_de_champ.find_by(libelle: type_pj.libelle) } let(:migrated_type_champ) { procedure.types_de_champ.find_by(libelle: type_pj.libelle) }

View file

@ -41,7 +41,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
describe 'procedure is published' do describe 'procedure is published' do
before do before do
procedure.publish!('fake_path') procedure.publish!(procedure.administrateurs.first, 'fake_path')
procedure.reload procedure.reload
render render
end end
@ -59,7 +59,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
describe 'procedure is archived' do describe 'procedure is archived' do
before do before do
procedure.publish!('fake_path') procedure.publish!(procedure.administrateurs.first, 'fake_path')
procedure.archive! procedure.archive!
procedure.reload procedure.reload
render render