Merge pull request #1399 from betagouv/fix-478
[Fix #478] /recherche can deal with very big int
This commit is contained in:
commit
b1c273e254
2 changed files with 31 additions and 4 deletions
|
@ -4,10 +4,9 @@ module NewGestionnaire
|
|||
@search_terms = params[:q]
|
||||
|
||||
# exact id match?
|
||||
if @search_terms.to_i != 0
|
||||
@dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i) +
|
||||
current_gestionnaire.dossiers_from_avis.where(id: @search_terms.to_i)
|
||||
@dossiers.uniq!
|
||||
id = @search_terms.to_i
|
||||
if id != 0 && id_compatible?(id) # Sometimes gestionnaire is searching dossiers with a big number (ex: SIRET), ActiveRecord can't deal with them and throws ActiveModel::RangeError. id_compatible? prevents this.
|
||||
@dossiers = dossiers_by_id(id)
|
||||
end
|
||||
|
||||
if @dossiers.nil?
|
||||
|
@ -23,5 +22,22 @@ module NewGestionnaire
|
|||
).results
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossiers_by_id(id)
|
||||
dossiers = current_gestionnaire.dossiers.where(id: id) +
|
||||
current_gestionnaire.dossiers_from_avis.where(id: id)
|
||||
dossiers.uniq
|
||||
end
|
||||
|
||||
def id_compatible?(number)
|
||||
begin
|
||||
ActiveRecord::Type::Integer.new.serialize(number)
|
||||
true
|
||||
rescue ActiveModel::RangeError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,17 @@ describe NewGestionnaire::RechercheController, type: :controller do
|
|||
expect(assigns(:dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an id out of range' do
|
||||
let(:query) { 123456789876543234567 }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'does not return the dossier' do
|
||||
subject
|
||||
expect(assigns(:dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue