Add translations to budget investments pg_search_scope

Some Budget::Investment attributes are now translatable so we need to
include all existing translations on pg_search model scope.
This commit is contained in:
Senén Rodero Rodríguez
2019-01-12 17:04:58 +01:00
committed by voodoorai2000
parent 9a459070e9
commit e8f53cb8b7
2 changed files with 20 additions and 6 deletions

View File

@@ -198,12 +198,10 @@ class Budget
end end
def searchable_values def searchable_values
{ title => "A", { author.username => "B",
author.username => "B",
heading.name => "B", heading.name => "B",
tag_list.join(" ") => "B", tag_list.join(" ") => "B"
description => "C" }.merge(searchable_globalized_values)
}
end end
def self.search(terms) def self.search(terms)
@@ -419,5 +417,10 @@ class Budget
end end
end end
end end
def searchable_translations_definitions
{ title => "A",
description => "D" }
end
end end
end end

View File

@@ -683,12 +683,23 @@ describe Budget::Investment do
context "attributes" do context "attributes" do
let(:attributes) { { title: "save the world",
description: "in order to save the world one must think about...",
title_es: "para salvar el mundo uno debe pensar en...",
description_es: "uno debe pensar" } }
it "searches by title" do it "searches by title" do
budget_investment = create(:budget_investment, title: "save the world") budget_investment = create(:budget_investment, attributes)
results = described_class.search("save the world") results = described_class.search("save the world")
expect(results).to eq([budget_investment]) expect(results).to eq([budget_investment])
end end
it "searches by title across all languages" do
budget_investment = create(:budget_investment, attributes)
results = described_class.search("salvar el mundo")
expect(results).to eq([budget_investment])
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")
budget_investment = create(:budget_investment, author: author) budget_investment = create(:budget_investment, author: author)