2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-08-29 19:08:27 +02:00
|
|
|
describe Gestionnaires::GroupeGestionnairesController, type: :controller do
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
|
|
|
|
describe "#index" do
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
context "when not logged" do
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2023-08-29 19:08:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
2023-09-28 17:45:39 +02:00
|
|
|
let!(:other_groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
|
|
|
let!(:not_my_groupe_gestionnaire) { create(:groupe_gestionnaire) }
|
2023-08-29 19:08:27 +02:00
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
|
|
|
end
|
|
|
|
|
2023-10-09 19:18:38 +02:00
|
|
|
it do
|
2023-12-10 18:25:58 +01:00
|
|
|
subject
|
2023-10-09 19:18:38 +02:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(assigns(:groupe_gestionnaires)).to include(groupe_gestionnaire)
|
|
|
|
expect(assigns(:groupe_gestionnaires)).to include(other_groupe_gestionnaire)
|
|
|
|
expect(assigns(:groupe_gestionnaires)).not_to include(not_my_groupe_gestionnaire)
|
|
|
|
end
|
2023-08-29 19:08:27 +02:00
|
|
|
end
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
|
|
|
|
describe "#show" do
|
|
|
|
subject { get :show, params: { id: child_groupe_gestionnaire.id } }
|
|
|
|
let!(:groupe_gestionnaire_root) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
2023-10-01 12:52:05 +02:00
|
|
|
let!(:child_groupe_gestionnaire) { create(:groupe_gestionnaire, ancestry: "/#{groupe_gestionnaire_root.id}/", gestionnaires: [gestionnaire]) }
|
2023-09-30 12:45:54 +02:00
|
|
|
|
|
|
|
context "when not logged" do
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
|
|
|
end
|
|
|
|
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(assigns(:groupe_gestionnaire)).to eq(child_groupe_gestionnaire)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#edit" do
|
|
|
|
subject { get :edit, params: { id: child_groupe_gestionnaire.id } }
|
|
|
|
let!(:groupe_gestionnaire_root) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
2023-10-01 12:52:05 +02:00
|
|
|
let!(:child_groupe_gestionnaire) { create(:groupe_gestionnaire, ancestry: "/#{groupe_gestionnaire_root.id}/", gestionnaires: [gestionnaire]) }
|
2023-09-30 12:45:54 +02:00
|
|
|
|
|
|
|
context "when not logged" do
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
|
|
|
end
|
|
|
|
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(assigns(:groupe_gestionnaire)).to eq(child_groupe_gestionnaire)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
subject { post :update, params: { id: child_groupe_gestionnaire.id, groupe_gestionnaire: { name: 'new child name' } } }
|
|
|
|
let!(:groupe_gestionnaire_root) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
2023-10-01 12:52:05 +02:00
|
|
|
let!(:child_groupe_gestionnaire) { create(:groupe_gestionnaire, ancestry: "/#{groupe_gestionnaire_root.id}/", gestionnaires: [gestionnaire]) }
|
2023-09-30 12:45:54 +02:00
|
|
|
|
|
|
|
context "when not logged" do
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
|
|
|
end
|
|
|
|
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(child_groupe_gestionnaire.reload.name).to eq('new child name')
|
|
|
|
expect(response).to redirect_to(gestionnaire_groupe_gestionnaire_path(child_groupe_gestionnaire))
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
subject { post :destroy, params: { id: child_groupe_gestionnaire.id } }
|
|
|
|
let!(:groupe_gestionnaire_root) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
2023-10-01 12:52:05 +02:00
|
|
|
let!(:child_groupe_gestionnaire) { create(:groupe_gestionnaire, ancestry: "/#{groupe_gestionnaire_root.id}/", gestionnaires: [gestionnaire]) }
|
2023-09-30 12:45:54 +02:00
|
|
|
|
|
|
|
context "when not logged" do
|
2023-12-10 18:25:58 +01:00
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
2023-12-10 18:25:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
2024-02-05 11:35:01 +01:00
|
|
|
expect(GroupeGestionnaire.count).to eq(1)
|
2023-12-10 18:25:58 +01:00
|
|
|
expect(response).to redirect_to(gestionnaire_groupe_gestionnaires_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#tree_structure" do
|
|
|
|
let!(:groupe_gestionnaire) { create(:groupe_gestionnaire, gestionnaires: [gestionnaire]) }
|
|
|
|
subject { get :tree_structure, params: { id: groupe_gestionnaire.id } }
|
|
|
|
|
|
|
|
context "when not logged" do
|
|
|
|
it do
|
2023-09-30 12:45:54 +02:00
|
|
|
subject
|
2023-12-10 18:25:58 +01:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
2023-12-10 18:25:58 +01:00
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
|
2023-12-10 18:25:58 +01:00
|
|
|
context "when logged in" do
|
|
|
|
let!(:child_groupe_gestionnaire) { create(:groupe_gestionnaire, ancestry: "/#{groupe_gestionnaire.id}/", gestionnaires: []) }
|
|
|
|
before do
|
|
|
|
sign_in(gestionnaire.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
subject
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(assigns(:tree_structure)).to eq(groupe_gestionnaire => { child_groupe_gestionnaire => {} })
|
|
|
|
end
|
2023-09-30 12:45:54 +02:00
|
|
|
end
|
|
|
|
end
|
2023-08-29 19:08:27 +02:00
|
|
|
end
|