Skip to content

Commit

Permalink
Merge pull request #4111 from ChrisBr/bugfix/project-autocomplete
Browse files Browse the repository at this point in the history
Remove subprojects from autocomplete
  • Loading branch information
David Kang committed Nov 6, 2017
2 parents e39c574 + 39dd9b7 commit 61f8121
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def autocomplete(search)
where.not("name rlike ?", ::Configuration.unlisted_projects_filter) if ::Configuration.unlisted_projects_filter.present?
}
scope :remote, -> { where('NOT ISNULL(projects.remoteurl)') }
scope :autocomplete, lambda { |search|
where("lower(name) like lower(?)", "#{search}%").where.not("lower(name) like lower(?)", "#{search}%:%")
}

# will return all projects with attribute 'OBS:ImageTemplates'
scope :local_image_templates, lambda {
Expand Down Expand Up @@ -209,15 +212,6 @@ def config
@config ||= ProjectConfigFile.new(project_name: name)
end

def self.autocomplete(search)
projects = Project.where(["lower(name) like lower(?)", "#{search}%"])
if search.to_s =~ /home:./
projects.home
else
projects.not_home
end
end

def self.deleted_instance
project = Project.find_by(name: 'deleted')
unless project
Expand Down
22 changes: 22 additions & 0 deletions src/api/spec/controllers/webui/project_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@
it { expect(@json_response).not_to include(apache_maintenance_incident_project.name) }
it { expect(@json_response).not_to include(openSUSE_project.name) }
end

context 'with a subprojects' do
let!(:apache_subproject) { create(:project, name: "Apache:subproject")}

context 'and searching for parent project' do
before do
get :autocomplete_projects, params: { term: 'Apache' }
@json_response = JSON.parse(response.body)
end

it { expect(@json_response).not_to include(apache_subproject.name) }
end

context 'and searching for parent project' do
before do
get :autocomplete_projects, params: { term: 'Apache:' }
@json_response = JSON.parse(response.body)
end

it { expect(@json_response).to include(apache_subproject.name) }
end
end
end

describe 'GET #autocomplete_incidents' do
Expand Down

0 comments on commit 61f8121

Please sign in to comment.