Merge branch 'develop' into staging

This commit is contained in:
Mathieu Magnin 2017-02-21 10:14:51 +01:00
commit 392d7455f9
2 changed files with 46 additions and 8 deletions

View file

@ -56,7 +56,10 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
@search_terms = params[:q] @search_terms = params[:q]
# exact id match? # exact id match?
@dossiers = Dossier.where(id: @search_terms.to_i) if @search_terms.to_i < 2147483647 if @search_terms.to_i != 0
@dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i)
end
@dossiers = Dossier.none if @dossiers.nil? @dossiers = Dossier.none if @dossiers.nil?
# full text search # full text search

View file

@ -5,16 +5,24 @@ describe Backoffice::DossiersController, type: :controller do
@request.env['HTTP_REFERER'] = TPS::Application::URL @request.env['HTTP_REFERER'] = TPS::Application::URL
end end
let(:procedure) { create :procedure } let(:procedure) { create :procedure }
let(:procedure2) { create :procedure }
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) } let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) }
let(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure2, state: :initiated) }
let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) } let(:dossier_archived) { create(:dossier, :with_entreprise, archived: true) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 } let(:bad_dossier_id) { Dossier.count + 10 }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) } let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
let!(:gestionnaire2) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
before do before do
create :assign_to, procedure: procedure, gestionnaire: gestionnaire create :assign_to, procedure: procedure, gestionnaire: gestionnaire
create :assign_to, procedure: procedure2, gestionnaire: gestionnaire2
procedure.dossiers << dossier
procedure2.dossiers << dossier2
end end
describe 'GET #index' do describe 'GET #index' do
@ -166,15 +174,42 @@ describe Backoffice::DossiersController, type: :controller do
end end
describe 'POST #search' do describe 'POST #search' do
before do describe 'by id' do
sign_in gestionnaire context 'when I am logged as a gestionnaire' do
end before do
sign_in gestionnaire
end
it 'returns http success' do context 'when I own the dossier' do
post :search, params: {search_terms: 'test'} before :each do
expect(response).to have_http_status(200) post :search, params: { q: dossier_id }
end end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns the expected dossier' do
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier_id)
end
end
context 'when I do not own the dossier' do
before :each do
post :search, params: { q: dossier2_id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns nothing' do
expect(assigns(:dossiers).count).to eq(0)
end
end
end
end
end end
describe 'POST #valid' do describe 'POST #valid' do