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 ...@@ -110,7 +110,7 @@ class Explore::ProjectsController < Explore::ApplicationController
end end
def load_topic def load_topic
@topic = Projects::Topic.find_by_name(params[:topic_name]) @topic = Projects::Topic.find_by_name_case_insensitive(params[:topic_name])
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -23,6 +23,10 @@ module Projects ...@@ -23,6 +23,10 @@ module Projects
end end
class << self class << self
def find_by_name_case_insensitive(name)
find_by('LOWER(name) = ?', name.downcase)
end
def search(query) def search(query)
fuzzy_search(query, [:name]) fuzzy_search(query, [:name])
end end
......
...@@ -112,6 +112,13 @@ RSpec.describe Explore::ProjectsController do ...@@ -112,6 +112,13 @@ RSpec.describe Explore::ProjectsController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('topic') expect(response).to render_template('topic')
end 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 end
end end
......
...@@ -56,6 +56,14 @@ RSpec.describe Projects::Topic do ...@@ -56,6 +56,14 @@ RSpec.describe Projects::Topic do
end end
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 describe '#search' do
it 'returns topics with a matching name' do it 'returns topics with a matching name' do
expect(described_class.search(topic.name)).to eq([topic]) 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