diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 45b24943e7..9e5d488e40 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -57,3 +57,4 @@ submit the change with your pull request. - Jake Yesbeck / [yez](https://github.com/yez) - Mauricio Gonzalez / [mauricio-gonzalez](https://github.com/mauricio-gonzalez) - Andrey Bazhutkin / [andrba](https://github.com/andrba) +- Gabriel Sandoval / [gabrielsandoval](https://github.com/gabrielsandoval) 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 new file mode 100644 index 0000000000..430ebd58dd --- /dev/null +++ b/app/views/places/_search_form.html.haml @@ -0,0 +1,6 @@ +%form{:action => search_places_path, :method => :get, :class => 'form-inline', :role => 'form'} + .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', :id => "search_button" +%br/ diff --git a/app/views/places/index.html.haml b/app/views/places/index.html.haml index 135d3a1139..a81dd6ba87 100644 --- a/app/views/places/index.html.haml +++ b/app/views/places/index.html.haml @@ -1,4 +1,4 @@ -content_for :title, "#{ENV['GROWSTUFF_SITE_NAME']} Community Map" - += render partial: 'search_form' %div#placesmap diff --git a/app/views/places/show.html.haml b/app/views/places/show.html.haml index b34846b395..8cc9f86efc 100644 --- a/app/views/places/show.html.haml +++ b/app/views/places/show.html.haml @@ -1,11 +1,6 @@ -content_for :title, "#{ENV['GROWSTUFF_SITE_NAME']} members near #{@place}" -%form{:action => search_places_path, :method => :get, :class => 'form-inline', :role => 'form'} - .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' -%br/ += render partial: 'search_form' %div#placesmap{ :style => "height:300px"} diff --git a/config/database.yml b/config/database.yml index 6b0ab15032..6aeb5d9616 100644 --- a/config/database.yml +++ b/config/database.yml @@ -3,6 +3,7 @@ development: database: growstuff_dev host: localhost user: postgres + password: password test: adapter: postgresql diff --git a/config/environments/test.rb b/config/environments/test.rb index 8d99b4e84c..c5c05f8d58 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -67,6 +67,20 @@ ] ) +Geocoder::Lookup::Test.add_stub( + "Philippines", [ + { + 'latitude' => 12.7503486, + 'longitude' => 122.7312101, + 'address' => 'Manila, Mnl, Philippines', + 'state' => 'Manila', + 'state_code' => 'Mnl', + 'country' => 'Philippines', + 'country_code' => 'PH' + } + ] +) + Geocoder::Lookup::Test.add_stub( "Greenwich, UK", [ { diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index 16de69ec00..0d221664e6 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -13,5 +13,4 @@ # Reported as https://github.com/alexreisner/geocoder/issues/509 if Geocoder.config.lookup != :test Geocoder.configure(:lookup => :nominatim) -end - +end \ No newline at end of file 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..6812e6413f --- /dev/null +++ b/spec/features/places/searching_a_place_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.feature "User searches", :type => :feature do + + scenario "with a valid place" do + visit places_path + search_with("Philippines") + expect(page).to have_content "members near Philippines" + expect(page).to have_button "search_button" + page.has_content?('placesmap') + expect(page).to have_content "Nearby members" + end + + scenario "with a blank search string" do + visit places_path + search_with("") + expect(page).to have_content "Please enter a valid location" + expect(page).to have_button "search_button" + page.has_content?('placesmap') + 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