Skip to content

Commit

Permalink
tests passing for stores controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ckundo committed Apr 8, 2012
1 parent d779f7c commit 4c14ec4
Show file tree
Hide file tree
Showing 43 changed files with 10,574 additions and 548 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
31 changes: 6 additions & 25 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,28 @@ source 'https://rubygems.org'

gem 'rails', '3.2.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'geocoder'
gem 'httparty'
gem 'nokogiri'

gem 'haml-rails'
gem 'jquery-rails'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'

gem 'uglifier', '>= 1.0.3'
end

group :test, :development do
group :development, :test do
gem 'sqlite3'
gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'vcr'
gem 'fakeweb'
end

gem 'jquery-rails'

group :production do
gem 'pg'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ GEM
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)
geocoder (1.1.1)
haml (3.1.4)
haml-rails (0.3.4)
Expand Down Expand Up @@ -118,11 +124,14 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
vcr (2.0.1)

PLATFORMS
ruby

DEPENDENCIES
factory_girl_rails
fakeweb
geocoder
haml-rails
httparty
Expand All @@ -134,3 +143,4 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
vcr
29 changes: 29 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)/assets/\w+/(.+\.(css|js|html)).*}) { |m| "/assets/#{m[2]}" }
end

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end


2 changes: 0 additions & 2 deletions app/assets/javascripts/products.js

This file was deleted.

39 changes: 36 additions & 3 deletions app/assets/javascripts/stores.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$.ajax({
url: '/stores.json',
dataType: 'json',
success: function(resp) {
mapper(resp);
},
error: function(resp) {
console.log('failed to get locations');
}
});

var mapper = function(locations) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(locations[0].latitude, locations[0].longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i].latitude, locations[i].longitude),
map: map
});

google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent("<p>" + locations[i].name + "</p>" + locations[i].phone);
infowindow.open(map, marker);
}
})(marker, i));
}
};
3 changes: 0 additions & 3 deletions app/assets/stylesheets/products.css.scss

This file was deleted.

Binary file added app/controllers/.stores_controller.rb.swp
Binary file not shown.
83 changes: 0 additions & 83 deletions app/controllers/products_controller.rb

This file was deleted.

12 changes: 7 additions & 5 deletions app/controllers/stores_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
require 'radar'

class StoresController < ApplicationController
def index
loc = request.location
default = loc.postal_code.empty? ? '10012' : loc.postal_code
zip = params['zip'] || default
coords = Geocoder.search(zip).first.coordinates #.first.data.fetch('geometry').fetch('location') if geo.empty?
@lat = coords[0]
@lng = coords[1]
Radar::Shack.scan(zip)
@locations = Store.near(zip)

coords = Geocoder.search(zip).first.coordinates
@location = {:latitude => coords[0], :longitude => coords[1]}

Radar::RadioShack.scan(zip)
@stores = Store.near(zip)

respond_to do |format|
format.html # index.html.erb
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/products_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/models/product.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/models/store.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
class Store < ActiveRecord::Base
has_many :products, :through => :inventory
geocoded_by :full_address
after_validation :geocode

def check_availability

end

def full_address
"#{self.address1}, #{self.address2}, #{self.city}, #{self.state} #{self.zip}"
end
Expand Down
16 changes: 0 additions & 16 deletions app/views/products/_form.html.haml

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/products/edit.html.haml

This file was deleted.

21 changes: 0 additions & 21 deletions app/views/products/index.html.haml

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/products/new.html.haml

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/products/show.html.haml

This file was deleted.

Loading

0 comments on commit 4c14ec4

Please sign in to comment.