2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-09 19:18:38 +02:00
|
|
|
describe Administrateurs::GroupeGestionnaireController, type: :controller do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:admin) { administrateurs(:default_admin) }
|
2023-10-09 19:18:38 +02:00
|
|
|
|
|
|
|
describe "#show" do
|
|
|
|
subject { get :show }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire], administrateurs: [admin]) }
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
it { expect(assigns(:groupe_gestionnaire)).to eq(groupe_gestionnaire) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#gestionnaires" do
|
|
|
|
subject { get :gestionnaires }
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire], administrateurs: [admin]) }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
it { expect(assigns(:groupe_gestionnaire)).to eq(groupe_gestionnaire) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#administrateurs" do
|
|
|
|
subject { get :administrateurs }
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire], administrateurs: [admin]) }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
it { expect(assigns(:groupe_gestionnaire)).to eq(groupe_gestionnaire) }
|
|
|
|
end
|
|
|
|
end
|
2023-10-24 17:45:20 +02:00
|
|
|
|
|
|
|
describe '#commentaires' do
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire], administrateurs: [admin]) }
|
|
|
|
subject { get :commentaires }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject).to have_http_status(:ok) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create_commentaire" do
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire], administrateurs: [admin]) }
|
|
|
|
let(:body) { "avant\napres" }
|
|
|
|
|
|
|
|
subject {
|
|
|
|
post :create_commentaire, params: {
|
2023-10-26 10:51:37 +02:00
|
|
|
commentaire_groupe_gestionnaire: {
|
2023-10-24 17:45:20 +02:00
|
|
|
body: body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
before { subject }
|
|
|
|
it { expect(response).to redirect_to(new_user_session_path) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
2023-12-10 18:25:58 +01:00
|
|
|
let(:gestionnaire_2) { create(:gestionnaire) }
|
|
|
|
|
2023-10-24 17:45:20 +02:00
|
|
|
before do
|
2023-12-10 18:25:58 +01:00
|
|
|
groupe_gestionnaire.gestionnaires << gestionnaire_2
|
2023-10-24 17:45:20 +02:00
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a commentaire" do
|
|
|
|
expect { subject }.to change(CommentaireGroupeGestionnaire, :count).by(1)
|
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_groupe_gestionnaire_commentaires_path)
|
|
|
|
expect(flash.notice).to be_present
|
|
|
|
end
|
2023-12-10 18:25:58 +01:00
|
|
|
|
|
|
|
it '2 emails are sent' do
|
|
|
|
expect { perform_enqueued_jobs { subject } }.to change { ActionMailer::Base.deliveries.count }.by(2)
|
|
|
|
end
|
2023-10-24 17:45:20 +02:00
|
|
|
end
|
|
|
|
end
|
2023-10-09 19:18:38 +02:00
|
|
|
end
|