Commit 5e953437 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'explore-topics/case-insensitive-name' into 'master'

Explore topics: find topic by case insensitive name for detail page

See merge request gitlab-org/gitlab!84064
parents 9f1bdb0a f55748d3
......@@ -110,7 +110,7 @@ class Explore::ProjectsController < Explore::ApplicationController
end
def load_topic
@topic = Projects::Topic.find_by_name(params[:topic_name])
@topic = Projects::Topic.find_by_name_case_insensitive(params[:topic_name])
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -23,6 +23,10 @@ module Projects
end
class << self
def find_by_name_case_insensitive(name)
find_by('LOWER(name) = ?', name.downcase)
end
def search(query)
fuzzy_search(query, [:name])
end
......
......@@ -112,6 +112,13 @@ RSpec.describe Explore::ProjectsController do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('topic')
end
it 'finds topic by case insensitive name' do
get :topic, params: { topic_name: 'TOPIC1' }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('topic')
end
end
end
end
......
......@@ -56,6 +56,14 @@ RSpec.describe Projects::Topic do
end
end
describe '#find_by_name_case_insensitive' do
it 'returns topic with case insensitive name' do
%w(topic TOPIC Topic).each do |name|
expect(described_class.find_by_name_case_insensitive(name)).to eq(topic)
end
end
end
describe '#search' do
it 'returns topics with a matching name' do
expect(described_class.search(topic.name)).to eq([topic])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment