Add translations to proposal pg_search_scope

Some Proposal attributes are now translatable so we need to include all
existing translations on pg_search scope.
This commit is contained in:
Senén Rodero Rodríguez
2019-01-12 14:56:06 +01:00
committed by voodoorai2000
parent 0f4fcfb20e
commit f572d5b579
3 changed files with 46 additions and 17 deletions

View File

@@ -125,14 +125,18 @@ class Proposal < ApplicationRecord
"#{id}-#{title}".parameterize "#{id}-#{title}".parameterize
end end
def searchable_values def searchable_translations_definitions
{ title => "A", { title => "A",
summary => "C",
description => "D" }
end
def searchable_values
{
author.username => "B", author.username => "B",
tag_list.join(" ") => "B", tag_list.join(" ") => "B",
geozone.try(:name) => "B", geozone.try(:name) => "B"
summary => "C", }.merge!(searchable_globalized_values)
description => "D"
}
end end
def self.search(terms) def self.search(terms)

View File

@@ -486,24 +486,49 @@ describe Proposal do
context "attributes" do context "attributes" do
let(:attributes) { { title: "save the world",
summary: "basically",
description: "in order to save the world one must think about...",
title_es: "para salvar el mundo uno debe pensar en...",
summary_es: "basicamente",
description_es: "uno debe pensar" } }
it "searches by title" do it "searches by title" do
proposal = create(:proposal, title: "save the world") proposal = create(:proposal, attributes)
results = described_class.search("save the world") results = described_class.search("save the world")
expect(results).to eq([proposal]) expect(results).to eq([proposal])
end end
it "searches by title across all languages translations" do
proposal = create(:proposal, attributes)
results = described_class.search("salvar el mundo")
expect(results).to eq([proposal])
end
it "searches by summary" do it "searches by summary" do
proposal = create(:proposal, summary: "basically...") proposal = create(:proposal, attributes)
results = described_class.search("basically") results = described_class.search("basically")
expect(results).to eq([proposal]) expect(results).to eq([proposal])
end end
it "searches by summary across all languages translations" do
proposal = create(:proposal, attributes)
results = described_class.search("basicamente")
expect(results).to eq([proposal])
end
it "searches by description" do it "searches by description" do
proposal = create(:proposal, description: "in order to save the world one must think about...") proposal = create(:proposal, attributes)
results = described_class.search("one must think") results = described_class.search("one must think")
expect(results).to eq([proposal]) expect(results).to eq([proposal])
end end
it "searches by description across all languages translations" do
proposal = create(:proposal, attributes)
results = described_class.search("uno debe pensar")
expect(results).to eq([proposal])
end
it "searches by author name" do it "searches by author name" do
author = create(:user, username: "Danny Trejo") author = create(:user, username: "Danny Trejo")
proposal = create(:proposal, author: author) proposal = create(:proposal, author: author)