Skip to content

Commit defc9b1

Browse files
authored
Handle no search params (#264)
1 parent 891fbbc commit defc9b1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/controllers/searches_controller.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ def new
66
end
77

88
def results
9-
@search = Search.new(search_params)
9+
begin
10+
@search = Search.new(search_params)
11+
rescue ActionController::ParameterMissing
12+
redirect_to search_path and return
13+
end
1014

1115
if @search.valid?
1216
respond_to do |format|

spec/requests/search_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@
2020
expect(response).to be_successful
2121
expect(response.body).to include("There is a problem")
2222
end
23+
24+
it "redirects when there are no search params" do
25+
get search_results_path
26+
expect(response).to redirect_to search_path
27+
end
2328
end

0 commit comments

Comments
 (0)