Commit f55748d3 authored by Jonas Wälter's avatar Jonas Wälter Committed by Jan Provaznik

Find topic by case insensitive name for detail page

Changelog: changed
parent 5e170ccc
......@@ -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