[fix #1097] Accent insensitive search
This commit is contained in:
parent
6a2b575027
commit
2bc61f9f3f
4 changed files with 13 additions and 3 deletions
|
@ -14,7 +14,7 @@ class FindDubiousProceduresJob < ApplicationJob
|
|||
# https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
|
||||
forbidden_tdcs = TypeDeChamp
|
||||
.joins(:procedure)
|
||||
.where("types_de_champ.libelle ~* '#{forbidden_regexp}'")
|
||||
.where("unaccent(types_de_champ.libelle) ~* unaccent('#{forbidden_regexp}')")
|
||||
.where(type_champ: %w(text textarea))
|
||||
.where(procedures: { archived_at: nil, whitelisted_at: nil })
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class EnableUnaccentPostgresqlExtension < ActiveRecord::Migration[5.0]
|
||||
def up
|
||||
execute 'CREATE EXTENSION unaccent;'
|
||||
end
|
||||
|
||||
def down
|
||||
execute 'DROP EXTENSION unaccent;'
|
||||
end
|
||||
end
|
|
@ -10,10 +10,11 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180105152235) do
|
||||
ActiveRecord::Schema.define(version: 20180108132507) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
enable_extension "unaccent"
|
||||
|
||||
create_table "administrateurs", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
|
|
|
@ -16,7 +16,7 @@ RSpec.describe FindDubiousProceduresJob, type: :job do
|
|||
|
||||
context 'with suspicious champs' do
|
||||
let(:forbidden_tdcs) do
|
||||
[create(:type_de_champ_public, libelle: 'donne ton iban, stp'),
|
||||
[create(:type_de_champ_public, libelle: 'num de securite sociale, stp'),
|
||||
create(:type_de_champ_public, libelle: "t'aurais une carte bancaire ?")]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue