diff --git a/app/models/debate.rb b/app/models/debate.rb index 0347f0edd..968431324 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -138,7 +138,7 @@ class Debate < ActiveRecord::Base end def self.search(terms) - terms.present? ? where("title ILIKE ? OR description ILIKE ?", "%#{terms}%", "%#{terms}%") : none + terms.present? ? where("unaccent(title) ILIKE unaccent(?) OR unaccent(description) ILIKE unaccent(?)", "%#{terms}%", "%#{terms}%") : none end def conflictive? diff --git a/db/migrate/20150910185110_add_unaccent_extension.rb b/db/migrate/20150910185110_add_unaccent_extension.rb new file mode 100644 index 000000000..d23af95d0 --- /dev/null +++ b/db/migrate/20150910185110_add_unaccent_extension.rb @@ -0,0 +1,9 @@ +class AddUnaccentExtension < ActiveRecord::Migration + def up + execute "CREATE EXTENSION IF NOT EXISTS unaccent" + end + + def down + execute "DROP EXTENSION unaccent" + end +end diff --git a/db/schema.rb b/db/schema.rb index fde03fe30..274192ccb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150910152734) do +ActiveRecord::Schema.define(version: 20150910185110) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + enable_extension "unaccent" create_table "addresses", force: :cascade do |t| t.integer "user_id" @@ -258,6 +259,7 @@ ActiveRecord::Schema.define(version: 20150910152734) do t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" t.string "letter_verification_code" + t.integer "letter_verification_tries", default: 0 end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index edb5c2725..bcddab7a4 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -439,10 +439,10 @@ feature 'Debates' do debate1 = create(:debate, title: "Show me what you got") debate2 = create(:debate, title: "Get Schwifty") debate3 = create(:debate) - debate4 = create(:debate, description: "Schwifty in here") + debate4 = create(:debate, description: "Schwíftÿ in here") visit debates_path - fill_in "search", with: "Schwifty" + fill_in "search", with: "Schwìfty" click_button "Search" within("#debates") do