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:
committed by
voodoorai2000
parent
0f4fcfb20e
commit
f572d5b579
@@ -23,15 +23,15 @@ module Globalizable
|
||||
|
||||
private
|
||||
|
||||
def searchable_globalized_values
|
||||
values = {}
|
||||
translations.each do |translation|
|
||||
Globalize.with_locale(translation.locale) do
|
||||
values.merge! searchable_translations_definitions
|
||||
def searchable_globalized_values
|
||||
values = {}
|
||||
translations.each do |translation|
|
||||
Globalize.with_locale(translation.locale) do
|
||||
values.merge! searchable_translations_definitions
|
||||
end
|
||||
end
|
||||
values
|
||||
end
|
||||
values
|
||||
end
|
||||
end
|
||||
|
||||
class_methods do
|
||||
|
||||
@@ -125,14 +125,18 @@ class Proposal < ApplicationRecord
|
||||
"#{id}-#{title}".parameterize
|
||||
end
|
||||
|
||||
def searchable_translations_definitions
|
||||
{ title => "A",
|
||||
summary => "C",
|
||||
description => "D" }
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => "A",
|
||||
author.username => "B",
|
||||
tag_list.join(" ") => "B",
|
||||
geozone.try(:name) => "B",
|
||||
summary => "C",
|
||||
description => "D"
|
||||
}
|
||||
{
|
||||
author.username => "B",
|
||||
tag_list.join(" ") => "B",
|
||||
geozone.try(:name) => "B"
|
||||
}.merge!(searchable_globalized_values)
|
||||
end
|
||||
|
||||
def self.search(terms)
|
||||
|
||||
@@ -486,24 +486,49 @@ describe Proposal 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
|
||||
proposal = create(:proposal, title: "save the world")
|
||||
proposal = create(:proposal, attributes)
|
||||
results = described_class.search("save the world")
|
||||
expect(results).to eq([proposal])
|
||||
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
|
||||
proposal = create(:proposal, summary: "basically...")
|
||||
proposal = create(:proposal, attributes)
|
||||
results = described_class.search("basically")
|
||||
expect(results).to eq([proposal])
|
||||
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
|
||||
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")
|
||||
expect(results).to eq([proposal])
|
||||
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
|
||||
author = create(:user, username: "Danny Trejo")
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
Reference in New Issue
Block a user