Skip to content

Commit

Permalink
[frontend] Handle nonexistent parameters as falsy
Browse files Browse the repository at this point in the history
This will allow us to drop some hidden fields from the search form
(5af7b8e).
Because of that change we have to add the default search parameters to
the form of the 'global-search-form'.
  • Loading branch information
bgeuken authored and Andreas Stieger committed Feb 2, 2018
1 parent f3ea108 commit a6b2347
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def set_parameters
@search_text = @search_text.delete("'[]\n")

@search_what = []
@search_what << 'package' if params[:package] == '1' || params[:package].nil?
@search_what << 'project' if params[:project] == '1' || params[:project].nil? && !@search_issue
@search_what << 'package' if params[:package] == '1'
@search_what << 'project' if params[:project] == '1' || !@search_issue
@search_what << 'owner' if params[:owner] == '1' && !@search_issue

@search_where = []
@search_where << 'name' if params[:name] == '1' || params[:name].nil?
@search_where << 'name' if params[:name] == '1'
@search_where << 'title' if params[:title] == '1'
@search_where << 'description' if params[:description] == '1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%li
= link_to(content_tag(:span, content_tag(:span, '', class: 'icons-project') + raw(project.gsub(':', ':<wbr>')),
class: 'project-link'), project_show_path(project))
= form_tag(search_path, { id: 'global-search-form', class: 'label-overlay' }) do
= form_tag(search_path(project: 1, package: 1, name: 1), { id: 'global-search-form', class: 'label-overlay' }) do
%div{ style: 'display: inline' }
%label.hidden{ for: 'search' } Search
= text_field_tag 'search_text', '', id: 'search'
Expand Down
8 changes: 4 additions & 4 deletions src/api/spec/controllers/webui/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
end
end

context 'with bad search_where' do
context 'with no search scope' do
before do
get :index, params: { search_text: 'whatever', name: '0' }
get :index, params: { search_text: 'whatever' }
end

it { expect(flash[:error]).to eq('You have to search for whatever in something. Click the advanced button...') }
Expand All @@ -92,7 +92,7 @@
context 'with proper parameters but no results' do
before do
allow(ThinkingSphinx).to receive(:search).and_return([])
get :index, params: { search_text: 'whatever' }
get :index, params: { search_text: 'whatever', project: 1, package: 1, name: 1 }
end

it { expect(flash[:notice]).to eq('Your search did not return any results.') }
Expand All @@ -103,7 +103,7 @@
context 'with proper parameters and some results' do
before do
allow(ThinkingSphinx).to receive(:search).and_return(["Fake result with #{package.name}"])
get :index, params: { search_text: package.name }
get :index, params: { search_text: package.name, project: 1, package: 1, name: 1 }
end

it { expect(response).to have_http_status(:success) }
Expand Down

0 comments on commit a6b2347

Please sign in to comment.