Commit 03cff6b7 authored by Chantal Rollison's avatar Chantal Rollison

Modified find project method to return nil if project not found

parent dd38a810
- project = find_project_for_result_blob(blob)
- return unless project
- file_name, blob = parse_search_result(blob)
- blob_link = project_blob_path(project, tree_join(blob.ref, file_name))
......
......@@ -11,7 +11,7 @@ module EE
override :find_project_for_result_blob
def find_project_for_result_blob(result)
super || ::Project.find(result['_parent'])
super || ::Project.find_by(id: result['_parent'])
end
override :parse_search_result
......
---
title: Don't show search results for projects that have been deleted when using elastic search
merge_request: 6830
author:
type: fixed
......@@ -36,6 +36,8 @@ describe 'Global elastic search' do
end
describe 'I search through the blobs' do
let(:project_2) { create(:project, :repository, :wiki_repo) }
before do
project.repository.index_blobs
......@@ -54,6 +56,28 @@ describe 'Global elastic search' do
expect(page).to have_selector("span.line[lang='javascript']")
end
it 'Ignores nonexistent projects from stale index' do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
project_2.repository.create_file(
user,
'thing.txt',
' function application.js ',
message: 'supercalifragilisticexpialidocious',
branch_name: 'master')
project_2.repository.index_blobs
Gitlab::Elastic::Helper.refresh_index
project_2.destroy
visit dashboard_projects_path
fill_in "search", with: "application.js"
click_button "Go"
expect(page).not_to have_content 'supercalifragilisticexpialidocious'
end
end
describe 'I search through the wiki blobs' do
......
......@@ -2,6 +2,8 @@ require 'spec_helper'
describe SearchHelper do
describe '#parse_search_result_from_elastic' do
let(:user) { create(:user) }
before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index
......@@ -32,5 +34,28 @@ describe SearchHelper do
expect(parsed_result.startline).to eq(2)
expect(parsed_result.data).to include("Popen")
end
it 'does not return project that does not exist' do
Gitlab::Elastic::Helper.create_empty_index
@project_2 = create :project, :repository
@project_2.repository.create_file(
user,
'thing.txt',
' function application.js ',
message: 'Find me',
branch_name: 'master')
@project_2.repository.index_blobs
Gitlab::Elastic::Helper.refresh_index
@project_2.destroy
blob = { _parent: @project_2.id }
result = find_project_for_result_blob(blob)
expect(result).to be(nil)
end
end
end
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