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
@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
end

View file

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

View file

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

View file

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

View file

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

View file

@ -1,10 +1,11 @@
require 'spec_helper'
describe APIController, type: :controller do
describe 'valid_token_for_administrateur?' do
let!(:admin) { create(:administrateur) }
describe 'valid_token_for_procedure?' do
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 '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) }
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))
subject
end

View file

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

View file

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

View file

@ -1,7 +1,7 @@
require 'spec_helper'
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) }
before do

View file

@ -652,7 +652,7 @@ describe Dossier do
let(:dossier) { create(:dossier, :en_construction) }
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).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

View file

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

View file

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

View file

@ -21,7 +21,7 @@ describe ProcedureSerializer do
p
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(: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
before do
procedure.publish!('fake_path')
procedure.publish!(procedure.administrateurs.first, 'fake_path')
procedure.reload
render
end
@ -59,7 +59,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
describe 'procedure is archived' do
before do
procedure.publish!('fake_path')
procedure.publish!(procedure.administrateurs.first, 'fake_path')
procedure.archive!
procedure.reload
render