Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ckundo/arduino-finder
base: 7195882b72
...
head fork: ckundo/arduino-finder
compare: 510149a541
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 15 files changed
  • 0 commit comments
  • 1 contributor
View
2  .gitignore
@@ -14,3 +14,5 @@
/log/*.log
/tmp
/spec/vcr_cassettes
+*.swp
+.DS_Store
View
4 Gemfile
@@ -19,12 +19,10 @@ end
group :development, :test do
gem 'sqlite3'
- gem 'cucumber'
- gem 'jasmine'
- gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'vcr'
gem 'fakeweb'
+ gem 'capybara'
end
group :production do
View
33 Gemfile.lock
@@ -30,6 +30,13 @@ GEM
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
@@ -39,26 +46,13 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
- cucumber (1.1.9)
- builder (>= 2.1.2)
- diff-lcs (>= 1.1.2)
- gherkin (~> 2.9.0)
- json (>= 1.4.6)
- term-ansicolor (>= 1.0.6)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
- factory_girl (3.0.0)
- activesupport (>= 3.0.0)
- factory_girl_rails (3.0.0)
- factory_girl (~> 3.0.0)
- railties (>= 3.0.0)
fakeweb (1.3.0)
ffi (1.0.11)
geocoder (1.1.1)
- gherkin (2.9.3)
- json (>= 1.4.6)
haml (3.1.4)
haml-rails (0.3.4)
actionpack (~> 3.0)
@@ -70,12 +64,6 @@ GEM
multi_json
multi_xml
i18n (0.6.0)
- jasmine (1.1.2)
- jasmine-core (>= 1.1.0)
- rack (>= 1.1)
- rspec (>= 1.3.1)
- selenium-webdriver (>= 0.1.3)
- jasmine-core (1.1.0)
journey (1.0.3)
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
@@ -145,7 +133,6 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
- term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -156,19 +143,19 @@ GEM
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
vcr (2.0.1)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
coffee-rails (~> 3.2.1)
- cucumber
- factory_girl_rails
fakeweb
geocoder
haml-rails
httparty
- jasmine
jquery-rails
nokogiri
pg
View
BIN  app/controllers/.stores_controller.rb.swo
Binary file not shown
View
BIN  app/controllers/.stores_controller.rb.swp
Binary file not shown
View
9 app/controllers/stores_controller.rb
@@ -2,14 +2,7 @@
class StoresController < ApplicationController
def index
- @zip = '10012'
- if !params[:latitude].blank? && !params[:longitude].blank?
- @zip = Geocoder.search("#{params[:latitude]},#{params[:longitude]}").first.postal_code
- elsif !params[:zip].blank?
- @zip = params[:zip]
- elsif !request.location.postal_code.blank?
- @zip = loc.postal_code
- end
+ @zip = Store.extract_zip_from_params!(params)
Radar::RadioShack.near(@zip)
@stores = Store.near(@zip)
View
16 app/models/store.rb
@@ -1,4 +1,9 @@
class Store < ActiveRecord::Base
+ BROOKLYN_ZIP = { :zip => '11231' }
+
+ NoPostalCodeError = Class.new(Exception)
+ NoLocationsError = Class.new(Exception)
+
geocoded_by :full_address
validates_presence_of :name, :city, :state
after_validation :geocode
@@ -6,4 +11,15 @@ class Store < ActiveRecord::Base
def full_address
"#{self.address1}, #{self.address2}, #{self.city}, #{self.state} #{self.zip}"
end
+
+ def self.extract_zip_from_params!(params)
+ location = params[:location] || BROOKLYN_ZIP
+ location_values = location.values.join(', ')
+
+ location_matches = Geocoder.search(location_values)
+
+ raise NoLocationsError if location_matches.empty?
+
+ location_matches.first.postal_code or raise NoPostalCodeError
+ end
end
View
9 db/migrate/20120414185226_change_zip_to_string.rb
@@ -0,0 +1,9 @@
+class ChangeZipToString < ActiveRecord::Migration
+ def up
+ change_column :stores, :zip, :string
+ end
+
+ def down
+ change_column :stores, :zip, :integer
+ end
+end
View
4 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120329164718) do
+ActiveRecord::Schema.define(:version => 20120414185226) do
create_table "inventories", :force => true do |t|
t.integer "product_id"
@@ -36,7 +36,7 @@
t.string "address2"
t.string "city"
t.string "state"
- t.integer "zip"
+ t.string "zip"
t.string "url"
t.string "phone"
t.datetime "created_at", :null => false
View
7 spec/acceptance/it_loads_spec.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+feature "home", :acceptance, :js do
+ example 'has map' do
+ visit '/'
+ end
+end
View
BIN  spec/controllers/.stores_controller_spec.rb.swo
Binary file not shown
View
BIN  spec/controllers/.stores_controller_spec.rb.swp
Binary file not shown
View
17 spec/controllers/stores_controller_spec.rb
@@ -9,19 +9,24 @@
Store.stub(:near) { [store] }
end
- it 'it assigns the zip code for a specified set of coordinates' do
- get :index, :latitude => "35.0522", :longitude => "-118.2428"
+ it 'assigns a zip given lat/lng params' do
+ get :index, :location => {
+ :latitude => "35.0522",
+ :longitude => "-118.2428"
+ }
assigns(:zip).should eql("93501")
end
- it 'it assigns the zip code for a specified zip code' do
- get :index, :zip => "91105"
+ it 'assigns a zip given zip param' do
+ get :index, :location => {
+ :zip => "91105"
+ }
assigns(:zip).should eql("91105")
end
- it 'sets a default location for the user' do
+ it 'assigns a default zip' do
get :index
- assigns(:zip).should eql("10012")
+ assigns(:zip).should eql("11231")
end
it 'assigns nearby stores to locations' do
View
55 spec/models/store_spec.rb
@@ -1,11 +1,58 @@
require 'spec_helper'
describe Store, :vcr do
+ let(:attributes) do
+ {
+ :name => 'Some store',
+ :address1 => '123 Main Street',
+ :address2 => '',
+ :city => 'Springfield',
+ :state => 'MA',
+ :zip => '03019'
+ }
+ end
+
+ let(:store) do
+ Store.create!(attributes)
+ end
+
+ let(:location) do
+ {
+ :latitude => 74.01,
+ :longitude => -110.01
+ }
+ end
+
describe '.full_address' do
- it 'should be a valid address' do
- store = Store.create!(:name => 'some name', :address1 => '123 Main Street',
- :address2 => '', :city => 'Springfield', :state => 'MA', :zip => '03019')
- store.full_address.should be_an_instance_of String
+ subject { store }
+
+ its(:full_address) do
+ should == "123 Main Street, , Springfield, MA 03019"
+ end
+ end
+
+ describe '.extract_zip_from_params' do
+ subject { Store.extract_zip_from_params!(params) }
+ let(:zip) { '11231' }
+ context 'params are a zipcode' do
+ let(:params) do
+ { :location => { :zip => zip } }
+ end
+ it { should == zip }
+ end
+ context 'params are coordinates' do
+ let(:params) do
+ { :location => {:latitude => 40.677280, :longitude => -74.009} }
+ end
+ it { should == zip }
+ end
+ context 'params are garbage' do
+ let(:params) do
+ { :location => {:foo => nil } }
+ end
+ it do
+ expect { subject }.to raise_error
+ end
end
end
end
View
5 spec/spec_helper.rb
@@ -3,6 +3,7 @@
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
+require 'capybara/rails'
require 'vcr'
# Requires supporting ruby files with custom matchers and macros, etc,
@@ -15,7 +16,11 @@
#c.configure_rspec_metadata!
#end
+Capybara.default_selector = :css
+Capybara.default_wait_time = 5
+
RSpec.configure do |config|
+ config.include Capybara::DSL, :type => :acceptance
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:

No commit comments for this range

Something went wrong with that request. Please try again.