|
7 | 7 | let(:gi) { assign_to.groupe_instructeur } |
8 | 8 | let(:from_admin) { nil } |
9 | 9 |
|
| 10 | + let(:other_procedure) { create(:procedure) } |
| 11 | + let(:other_assign_to) { create(:assign_to, instructeur: instructeur, groupe_instructeur: build(:groupe_instructeur, procedure: other_procedure)) } |
| 12 | + let(:other_gi) { other_assign_to.groupe_instructeur } |
| 13 | + |
10 | 14 | before do |
11 | 15 | sign_in(instructeur.user) |
12 | 16 | end |
|
116 | 120 | expect(response).to redirect_to(instructeur_groupe_path(gi, procedure_id: procedure.id)) |
117 | 121 | end |
118 | 122 | end |
| 123 | + |
| 124 | + context 'when procedure_id and groupe_id belong to different procedures' do |
| 125 | + before do |
| 126 | + gi # instructeur has legitimate access to `procedure` via gi |
| 127 | + other_gi # instructeur is also a member of other_gi on other_procedure |
| 128 | + end |
| 129 | + |
| 130 | + let(:valid_contact_information_params) do |
| 131 | + { |
| 132 | + nom: 'cross service', |
| 133 | + email: 'email@toto.com', |
| 134 | + telephone: '1234', |
| 135 | + horaires: 'horaires', |
| 136 | + adresse: 'adresse', |
| 137 | + } |
| 138 | + end |
| 139 | + |
| 140 | + describe '#create' do |
| 141 | + subject(:mismatched_create) do |
| 142 | + post :create, params: { |
| 143 | + contact_information: valid_contact_information_params, |
| 144 | + procedure_id: procedure.id, |
| 145 | + groupe_id: other_gi.id, |
| 146 | + } |
| 147 | + end |
| 148 | + |
| 149 | + it 'does not create a contact_information on the other procedure groupe' do |
| 150 | + expect { mismatched_create rescue nil }.not_to change { ContactInformation.count } |
| 151 | + expect(other_gi.reload.contact_information).to be_nil |
| 152 | + end |
| 153 | + end |
| 154 | + |
| 155 | + describe '#update' do |
| 156 | + let!(:other_contact_information) { create(:contact_information, groupe_instructeur: other_gi, nom: 'original') } |
| 157 | + |
| 158 | + subject(:mismatched_update) do |
| 159 | + patch :update, params: { |
| 160 | + id: other_contact_information.id, |
| 161 | + contact_information: { nom: 'tampered' }, |
| 162 | + procedure_id: procedure.id, |
| 163 | + groupe_id: other_gi.id, |
| 164 | + } |
| 165 | + end |
| 166 | + |
| 167 | + it 'does not modify the other procedure groupe contact_information' do |
| 168 | + expect { mismatched_update rescue nil }.not_to change { other_contact_information.reload.nom } |
| 169 | + end |
| 170 | + end |
| 171 | + |
| 172 | + describe '#destroy' do |
| 173 | + let!(:other_contact_information) { create(:contact_information, groupe_instructeur: other_gi) } |
| 174 | + |
| 175 | + subject(:mismatched_destroy) do |
| 176 | + delete :destroy, params: { |
| 177 | + id: other_contact_information.id, |
| 178 | + procedure_id: procedure.id, |
| 179 | + groupe_id: other_gi.id, |
| 180 | + } |
| 181 | + end |
| 182 | + |
| 183 | + it 'does not destroy the other procedure groupe contact_information' do |
| 184 | + expect { mismatched_destroy rescue nil }.not_to change { ContactInformation.exists?(other_contact_information.id) } |
| 185 | + end |
| 186 | + end |
| 187 | + end |
119 | 188 | end |
0 commit comments