2017-06-29 15:30:42 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NewGestionnaire::ProceduresController, type: :controller do
|
2017-07-04 10:26:50 +02:00
|
|
|
describe "before_action: ensure_ownership!" do
|
|
|
|
it "is present" do
|
2017-06-29 15:30:42 +02:00
|
|
|
before_actions = NewGestionnaire::ProceduresController
|
|
|
|
._process_action_callbacks
|
|
|
|
.find_all{|process_action_callbacks| process_action_callbacks.kind == :before}
|
|
|
|
.map(&:filter)
|
|
|
|
|
|
|
|
expect(before_actions).to include(:ensure_ownership!)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
describe "ensure_ownership!" do
|
2017-06-29 15:30:42 +02:00
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
@controller.params[:procedure_id] = asked_procedure.id
|
|
|
|
expect(@controller).to receive(:current_gestionnaire).and_return(gestionnaire)
|
|
|
|
allow(@controller).to receive(:redirect_to)
|
|
|
|
|
|
|
|
@controller.send(:ensure_ownership!)
|
|
|
|
end
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
context "when a gestionnaire asks for its procedure" do
|
2017-06-29 15:30:42 +02:00
|
|
|
let(:asked_procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
it "does not redirects nor flash" do
|
2017-06-29 15:30:42 +02:00
|
|
|
expect(@controller).not_to have_received(:redirect_to)
|
|
|
|
expect(flash.alert).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
context "when a gestionnaire asks for another procedure" do
|
2017-06-29 15:30:42 +02:00
|
|
|
let(:asked_procedure) { create(:procedure) }
|
|
|
|
|
2017-07-04 10:26:50 +02:00
|
|
|
it "redirects and flash" do
|
2017-06-29 15:30:42 +02:00
|
|
|
expect(@controller).to have_received(:redirect_to).with(root_path)
|
|
|
|
expect(flash.alert).to eq("Vous n'avez pas accès à cette procédure")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|