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

Commit

Permalink
Merge pull request Growstuff#751 from GabrielSandoval/search_form
Browse files Browse the repository at this point in the history
Added search form on the places index page.
  • Loading branch information
pozorvlak committed Jul 1, 2015
2 parents daa8717 + 429e547 commit 4648464
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 12 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
6 changes: 6 additions & 0 deletions app/views/places/_search_form.html.haml
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion app/views/places/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-content_for :title, "#{ENV['GROWSTUFF_SITE_NAME']} Community Map"

= render partial: 'search_form'
%div#placesmap

7 changes: 1 addition & 6 deletions app/views/places/show.html.haml
Original file line number Diff line number Diff line change
@@ -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"}

Expand Down
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ development:
database: growstuff_dev
host: localhost
user: postgres
password: password

test:
adapter: postgresql
Expand Down
14 changes: 14 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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", [
{
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
# Reported as https://github.com/alexreisner/geocoder/issues/509
if Geocoder.config.lookup != :test
Geocoder.configure(:lookup => :nominatim)
end

end
27 changes: 27 additions & 0 deletions spec/features/places/searching_a_place_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4648464

Please sign in to comment.