From e8f53cb8b7feee618aa72c7479afffc86b1b620e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Sat, 12 Jan 2019 17:04:58 +0100 Subject: [PATCH] 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. --- app/models/budget/investment.rb | 13 ++++++++----- spec/models/budget/investment_spec.rb | 13 ++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 15bb3a2f4..aa83a499a 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -198,12 +198,10 @@ class Budget end def searchable_values - { title => "A", - author.username => "B", + { author.username => "B", heading.name => "B", - tag_list.join(" ") => "B", - description => "C" - } + tag_list.join(" ") => "B" + }.merge(searchable_globalized_values) end def self.search(terms) @@ -419,5 +417,10 @@ class Budget end end end + + def searchable_translations_definitions + { title => "A", + description => "D" } + end end end diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 65865b211..37d015d8b 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -683,12 +683,23 @@ describe Budget::Investment 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 - budget_investment = create(:budget_investment, title: "save the world") + budget_investment = create(:budget_investment, attributes) results = described_class.search("save the world") expect(results).to eq([budget_investment]) 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 author = create(:user, username: "Danny Trejo") budget_investment = create(:budget_investment, author: author)