Get search dictionary based on I18n.default_locale (merge pull request #3856)
Implementation tries to be open for further extensions, such as deciding on search dictionary based on configuration option or by locale set for given user.
This commit is contained in:
committed by
GitHub
parent
426c1c5fd2
commit
d99875cde2
@@ -1410,7 +1410,7 @@ describe "Proposals" do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Order by relevance by default", :js do
|
||||
scenario "Order by relevance by default", :spanish_search, :js do
|
||||
create(:proposal, title: "Show you got", cached_votes_up: 10)
|
||||
create(:proposal, title: "Show what you got", cached_votes_up: 1)
|
||||
create(:proposal, title: "Show you got", cached_votes_up: 100)
|
||||
|
||||
30
spec/lib/search_dictionary_selector_spec.rb
Normal file
30
spec/lib/search_dictionary_selector_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe SearchDictionarySelector do
|
||||
context "from I18n default locale" do
|
||||
before { allow(subject).to receive(:call).and_call_original }
|
||||
around do |example|
|
||||
original_i18n_default = I18n.default_locale
|
||||
begin
|
||||
example.run
|
||||
ensure
|
||||
I18n.default_locale = original_i18n_default
|
||||
end
|
||||
end
|
||||
|
||||
it "returns correct dictionary for simple locale" do
|
||||
I18n.default_locale = :es
|
||||
expect(subject.call).to eq("spanish")
|
||||
end
|
||||
|
||||
it "returns correct dictionary for compound locale" do
|
||||
I18n.default_locale = :"pt-BR"
|
||||
expect(subject.call).to eq("portuguese")
|
||||
end
|
||||
|
||||
it "returns simple for unsupported locale" do
|
||||
expect(I18n).to receive(:default_locale).and_return(:pl) # avoiding I18n::InvalidLocale
|
||||
expect(subject.call).to eq("simple")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -503,7 +503,7 @@ describe Debate do
|
||||
end
|
||||
|
||||
context "stemming" do
|
||||
it "searches word stems" do
|
||||
it "searches word stems in Spanish", :spanish_search do
|
||||
debate = create(:debate, title: "limpiar")
|
||||
|
||||
results = Debate.search("limpiará")
|
||||
|
||||
@@ -558,7 +558,7 @@ describe Proposal do
|
||||
end
|
||||
|
||||
context "case" do
|
||||
it "searches case insensite" do
|
||||
it "searches case insensitive" do
|
||||
proposal = create(:proposal, title: "SHOUT")
|
||||
|
||||
results = Proposal.search("shout")
|
||||
|
||||
@@ -128,6 +128,10 @@ RSpec.configure do |config|
|
||||
allow(Time).to receive(:zone).and_return(application_zone)
|
||||
end
|
||||
|
||||
config.before(:each, :spanish_search) do |example|
|
||||
allow(SearchDictionarySelector).to receive(:call).and_return("spanish")
|
||||
end
|
||||
|
||||
# Allows RSpec to persist some state between runs in order to support
|
||||
# the `--only-failures` and `--next-failure` CLI options.
|
||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||
|
||||
Reference in New Issue
Block a user