From 87f1c6c26dc450f55ce097043f51cbb491af6920 Mon Sep 17 00:00:00 2001 From: AELOGICA Date: Tue, 23 Jun 2015 14:33:13 +0800 Subject: [PATCH] Added an alert for empty string search. --- Gemfile.lock | 3 --- app/controllers/places_controller.rb | 14 +++++++++--- app/views/places/_search_form.html.haml | 2 +- .../features/places/searching_a_place_spec.rb | 22 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 spec/features/places/searching_a_place_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 7e3b4aa927..fef7b8258d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -458,6 +458,3 @@ DEPENDENCIES unicorn webrat will_paginate (~> 3.0) - -BUNDLED WITH - 1.10.3 diff --git a/app/controllers/places_controller.rb b/app/controllers/places_controller.rb index 54ca249fdf..82189cb687 100644 --- a/app/controllers/places_controller.rb +++ b/app/controllers/places_controller.rb @@ -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 diff --git a/app/views/places/_search_form.html.haml b/app/views/places/_search_form.html.haml index e9f801c17b..430ebd58dd 100644 --- a/app/views/places/_search_form.html.haml +++ b/app/views/places/_search_form.html.haml @@ -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/ diff --git a/spec/features/places/searching_a_place_spec.rb b/spec/features/places/searching_a_place_spec.rb new file mode 100644 index 0000000000..614fe91880 --- /dev/null +++ b/spec/features/places/searching_a_place_spec.rb @@ -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 \ No newline at end of file