Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Added an alert for empty string search.
Browse files Browse the repository at this point in the history
  • Loading branch information
AELOGICA committed Jun 23, 2015
1 parent 0e2a5fd commit 87f1c6c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,3 @@ DEPENDENCIES
unicorn
webrat
will_paginate (~> 3.0)

BUNDLED WITH
1.10.3
14 changes: 11 additions & 3 deletions app/controllers/places_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ def show
end

def search
respond_to do |format|
format.html do
redirect_to place_path(params[:new_place])
if params[:new_place].empty?
respond_to do |format|
format.html do
redirect_to places_path, alert: 'Please enter a valid location'
end
end
else
respond_to do |format|
format.html do
redirect_to place_path(params[:new_place])
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/places/_search_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
.form-group
= label_tag :new_place, "Change location:", :class => 'sr-only'
= text_field_tag :new_place, '', :class => 'form-control', :placeholder => "New location..."
= submit_tag "Search", :class => 'btn btn-primary'
= submit_tag "Search", :class => 'btn btn-primary', :id => "search_button"
%br/
22 changes: 22 additions & 0 deletions spec/features/places/searching_a_place_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "rails_helper"

RSpec.feature "User searches", :type => :feature do

scenario "with a valid place" do
visit "/places"
search_with("Philippines")
assert true
end

scenario "with a blank search string" do
visit "/places"
search_with("")
assert true
end

def search_with(search_string)
fill_in "new_place", :with => search_string
click_button "search_button"
end

end

0 comments on commit 87f1c6c

Please sign in to comment.