Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests passing for stores controller

  • Loading branch information...
commit 4c14ec4ad49aec1d453d4292237cfbb75cea8bb0 1 parent d779f7c
@ckundo authored
Showing with 10,574 additions and 548 deletions.
  1. +1 −0  .rspec
  2. +6 −25 Gemfile
  3. +10 −0 Gemfile.lock
  4. +29 −0 Guardfile
  5. +0 −2  app/assets/javascripts/products.js
  6. +36 −3 app/assets/javascripts/stores.js
  7. +0 −3  app/assets/stylesheets/products.css.scss
  8. BIN  app/controllers/.stores_controller.rb.swp
  9. +0 −83 app/controllers/products_controller.rb
  10. +7 −5 app/controllers/stores_controller.rb
  11. +0 −2  app/helpers/products_helper.rb
  12. +0 −4 app/models/product.rb
  13. +0 −5 app/models/store.rb
  14. +0 −16 app/views/products/_form.html.haml
  15. +0 −7 app/views/products/edit.html.haml
  16. +0 −21 app/views/products/index.html.haml
  17. +0 −5 app/views/products/new.html.haml
  18. +0 −12 app/views/products/show.html.haml
  19. +0 −40 app/views/stores/index.html.erb
  20. +0 −10 db/migrate/20120329164718_create_products.rb
  21. +1 −2  lib/radar.rb
  22. BIN  spec/controllers/.stores_controller_spec.rb.swp
  23. +0 −164 spec/controllers/products_controller_spec.rb
  24. +30 −0 spec/controllers/stores_controller_spec.rb
  25. +0 −15 spec/helpers/products_helper_spec.rb
  26. +17 −0 spec/lib/radar_spec.rb
  27. +0 −5 spec/models/product_spec.rb
  28. +11 −0 spec/models/store_spec.rb
  29. +4 −4 spec/requests/{products_spec.rb → stores_spec.rb}
  30. +0 −35 spec/routing/products_routing_spec.rb
  31. +40 −0 spec/spec_helper.rb
  32. +1,688 −0 spec/vcr_cassettes/Radar/given_a_location/should_return_a_list_of_stores_with_arduino_unos_in_stock.yml
  33. +164 −0 spec/vcr_cassettes/Store/_full_address/should_be_a_valid_address.yml
  34. +1,359 −0 spec/vcr_cassettes/StoresController/GET_index/assigns_float_coordinates_to_lat_and_lng.yml
  35. +1,290 −0 spec/vcr_cassettes/StoresController/GET_index/assigns_nearby_stores_to_locations.yml
  36. +1,764 −0 spec/vcr_cassettes/StoresController/GET_index/defaults_to_params_for_location.yml
  37. +1,396 −0 spec/vcr_cassettes/StoresController/GET_index/geolocates_the_user_by_ip.yml
  38. +1,359 −0 spec/vcr_cassettes/StoresController/GET_index/sets_a_default_location_for_the_user.yml
  39. +1,362 −0 spec/vcr_cassettes/StoresController/GET_index/should_render_the_proper_view.yml
  40. +0 −20 spec/views/products/edit.html.haml_spec.rb
  41. +0 −23 spec/views/products/index.html.haml_spec.rb
  42. +0 −20 spec/views/products/new.html.haml_spec.rb
  43. +0 −17 spec/views/products/show.html.haml_spec.rb
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
31 Gemfile
@@ -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'
View
10 Gemfile.lock
@@ -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)
@@ -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
@@ -134,3 +143,4 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
+ vcr
View
29 Guardfile
@@ -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
+
+
View
2  app/assets/javascripts/products.js
@@ -1,2 +0,0 @@
-// Place all the behaviors and hooks related to the matching controller here.
-// All this logic will automatically be available in application.js.
View
39 app/assets/javascripts/stores.js
@@ -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));
+ }
+};
View
3  app/assets/stylesheets/products.css.scss
@@ -1,3 +0,0 @@
-// Place all the styles related to the Products controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
View
BIN  app/controllers/.stores_controller.rb.swp
Binary file not shown
View
83 app/controllers/products_controller.rb
@@ -1,83 +0,0 @@
-class ProductsController < ApplicationController
- # GET /products
- # GET /products.json
- def index
- @products = Product.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @products }
- end
- end
-
- # GET /products/1
- # GET /products/1.json
- def show
- @product = Product.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @product }
- end
- end
-
- # GET /products/new
- # GET /products/new.json
- def new
- @product = Product.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @product }
- end
- end
-
- # GET /products/1/edit
- def edit
- @product = Product.find(params[:id])
- end
-
- # POST /products
- # POST /products.json
- def create
- @product = Product.new(params[:product])
-
- respond_to do |format|
- if @product.save
- format.html { redirect_to @product, notice: 'Product was successfully created.' }
- format.json { render json: @product, status: :created, location: @product }
- else
- format.html { render action: "new" }
- format.json { render json: @product.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PUT /products/1
- # PUT /products/1.json
- def update
- @product = Product.find(params[:id])
-
- respond_to do |format|
- if @product.update_attributes(params[:product])
- format.html { redirect_to @product, notice: 'Product was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @product.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /products/1
- # DELETE /products/1.json
- def destroy
- @product = Product.find(params[:id])
- @product.destroy
-
- respond_to do |format|
- format.html { redirect_to products_url }
- format.json { head :no_content }
- end
- end
-end
View
12 app/controllers/stores_controller.rb
@@ -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
View
2  app/helpers/products_helper.rb
@@ -1,2 +0,0 @@
-module ProductsHelper
-end
View
4 app/models/product.rb
@@ -1,4 +0,0 @@
-class Product < ActiveRecord::Base
- belongs_to :inventory
-
-end
View
5 app/models/store.rb
@@ -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
View
16 app/views/products/_form.html.haml
@@ -1,16 +0,0 @@
-= form_for @product do |f|
- -if @product.errors.any?
- #error_explanation
- %h2= "#{pluralize(@product.errors.count, "error")} prohibited this product from being saved:"
- %ul
- - @product.errors.full_messages.each do |msg|
- %li= msg
-
- .field
- = f.label :name
- = f.text_field :name
- .field
- = f.label :part_number
- = f.text_field :part_number
- .actions
- = f.submit 'Save'
View
7 app/views/products/edit.html.haml
@@ -1,7 +0,0 @@
-%h1 Editing product
-
-= render 'form'
-
-= link_to 'Show', @product
-\|
-= link_to 'Back', products_path
View
21 app/views/products/index.html.haml
@@ -1,21 +0,0 @@
-%h1 Listing products
-
-%table
- %tr
- %th Name
- %th Part number
- %th
- %th
- %th
-
- - @products.each do |product|
- %tr
- %td= product.name
- %td= product.part_number
- %td= link_to 'Show', product
- %td= link_to 'Edit', edit_product_path(product)
- %td= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete
-
-%br
-
-= link_to 'New Product', new_product_path
View
5 app/views/products/new.html.haml
@@ -1,5 +0,0 @@
-%h1 New product
-
-= render 'form'
-
-= link_to 'Back', products_path
View
12 app/views/products/show.html.haml
@@ -1,12 +0,0 @@
-%p#notice= notice
-
-%p
- %b Name:
- = @product.name
-%p
- %b Part number:
- = @product.part_number
-
-= link_to 'Edit', edit_product_path(@product)
-\|
-= link_to 'Back', products_path
View
40 app/views/stores/index.html.erb
@@ -1,42 +1,2 @@
<div id="map" style="width:100%; height:100%;"></div>
-
-<script type="text/javascript">
-
- $.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));
- }
- };
-</script>
View
10 db/migrate/20120329164718_create_products.rb
@@ -1,10 +0,0 @@
-class CreateProducts < ActiveRecord::Migration
- def change
- create_table :products do |t|
- t.string :name
- t.string :part_number
-
- t.timestamps
- end
- end
-end
View
3  lib/radar.rb
@@ -1,9 +1,8 @@
module Radar
- class Shack
+ class RadioShack
@base_uri = 'http://www.radioshack.com'
def self.scan(zip = 10012, product_id = 12268262)
-
query = {:productId => product_id, :zip => zip}
resp = HTTParty.get("#{@base_uri}/product/inStoreAvail.jsp", :query => query, :format => :html)
doc = Nokogiri::HTML(resp)
View
BIN  spec/controllers/.stores_controller_spec.rb.swp
Binary file not shown
View
164 spec/controllers/products_controller_spec.rb
@@ -1,164 +0,0 @@
-require 'spec_helper'
-
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
-describe ProductsController do
-
- # This should return the minimal set of attributes required to create a valid
- # Product. As you add validations to Product, be sure to
- # update the return value of this method accordingly.
- def valid_attributes
- {}
- end
-
- # This should return the minimal set of values that should be in the session
- # in order to pass any filters (e.g. authentication) defined in
- # ProductsController. Be sure to keep this updated too.
- def valid_session
- {}
- end
-
- describe "GET index" do
- it "assigns all products as @products" do
- product = Product.create! valid_attributes
- get :index, {}, valid_session
- assigns(:products).should eq([product])
- end
- end
-
- describe "GET show" do
- it "assigns the requested product as @product" do
- product = Product.create! valid_attributes
- get :show, {:id => product.to_param}, valid_session
- assigns(:product).should eq(product)
- end
- end
-
- describe "GET new" do
- it "assigns a new product as @product" do
- get :new, {}, valid_session
- assigns(:product).should be_a_new(Product)
- end
- end
-
- describe "GET edit" do
- it "assigns the requested product as @product" do
- product = Product.create! valid_attributes
- get :edit, {:id => product.to_param}, valid_session
- assigns(:product).should eq(product)
- end
- end
-
- describe "POST create" do
- describe "with valid params" do
- it "creates a new Product" do
- expect {
- post :create, {:product => valid_attributes}, valid_session
- }.to change(Product, :count).by(1)
- end
-
- it "assigns a newly created product as @product" do
- post :create, {:product => valid_attributes}, valid_session
- assigns(:product).should be_a(Product)
- assigns(:product).should be_persisted
- end
-
- it "redirects to the created product" do
- post :create, {:product => valid_attributes}, valid_session
- response.should redirect_to(Product.last)
- end
- end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved product as @product" do
- # Trigger the behavior that occurs when invalid params are submitted
- Product.any_instance.stub(:save).and_return(false)
- post :create, {:product => {}}, valid_session
- assigns(:product).should be_a_new(Product)
- end
-
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- Product.any_instance.stub(:save).and_return(false)
- post :create, {:product => {}}, valid_session
- response.should render_template("new")
- end
- end
- end
-
- describe "PUT update" do
- describe "with valid params" do
- it "updates the requested product" do
- product = Product.create! valid_attributes
- # Assuming there are no other products in the database, this
- # specifies that the Product created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- Product.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, {:id => product.to_param, :product => {'these' => 'params'}}, valid_session
- end
-
- it "assigns the requested product as @product" do
- product = Product.create! valid_attributes
- put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
- assigns(:product).should eq(product)
- end
-
- it "redirects to the product" do
- product = Product.create! valid_attributes
- put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
- response.should redirect_to(product)
- end
- end
-
- describe "with invalid params" do
- it "assigns the product as @product" do
- product = Product.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Product.any_instance.stub(:save).and_return(false)
- put :update, {:id => product.to_param, :product => {}}, valid_session
- assigns(:product).should eq(product)
- end
-
- it "re-renders the 'edit' template" do
- product = Product.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Product.any_instance.stub(:save).and_return(false)
- put :update, {:id => product.to_param, :product => {}}, valid_session
- response.should render_template("edit")
- end
- end
- end
-
- describe "DELETE destroy" do
- it "destroys the requested product" do
- product = Product.create! valid_attributes
- expect {
- delete :destroy, {:id => product.to_param}, valid_session
- }.to change(Product, :count).by(-1)
- end
-
- it "redirects to the products list" do
- product = Product.create! valid_attributes
- delete :destroy, {:id => product.to_param}, valid_session
- response.should redirect_to(products_url)
- end
- end
-
-end
View
30 spec/controllers/stores_controller_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe StoresController do
+ describe 'GET index', :vcr do
+ let(:store) { stub_model(Store) }
+
+ before(:each) do
+ Radar::RadioShack.stub(:scan) {[store]}
+ Geocoder.stub_chain(:search, :first, :coordinates).and_return([73.2,-132.2])
+ Geocoder.stub_chain(:search, :first, :postal_code).and_return('11231')
+ Store.stub(:near) { [store] }
+ end
+
+ it 'sets a default location for the user' do
+ get :index
+ assigns(:location).should eql({"latitude" => 73.2, "longitude" => -132.2})
+ end
+
+ it 'assigns nearby stores to locations' do
+ get :index
+ response.should be_success
+ assigns(:stores).should eq([store])
+ end
+
+ it 'should render the proper view' do
+ get :index, :format => 'html'
+ response.should render_template('stores/index')
+ end
+ end
+end
View
15 spec/helpers/products_helper_spec.rb
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the ProductsHelper. For example:
-#
-# describe ProductsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
-describe ProductsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
View
17 spec/lib/radar_spec.rb
@@ -0,0 +1,17 @@
+require "spec_helper"
+
+describe Radar, :vcr do
+ context "given a location" do
+ it "should return a list of stores with arduino unos in stock" do
+ location = 11231
+ stores = Radar::RadioShack.scan(location)
+ stores.should be_an_instance_of Array
+ stores.should_not be_empty
+ stores.each do |s|
+ s.should be_an_instance_of Store
+ s.should_not be_nil
+ end
+ end
+ end
+end
+
View
5 spec/models/product_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe Product do
- pending "add some examples to (or delete) #{__FILE__}"
-end
View
11 spec/models/store_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Store, :vcr do
+ describe '.full_address' do
+ it 'should be a valid address' do
+ store = Store.create!(:address1 => '123 Main Street',
+ :address2 => '', :city => 'Springfield', :state => 'MA', :zip => '03019')
+ store.full_address.should be_an_instance_of String
+ end
+ end
+end
View
8 spec/requests/products_spec.rb → spec/requests/stores_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-describe "Products" do
- describe "GET /products" do
- it "works! (now write some real specs)" do
+describe "Stores", :vcr do
+ describe "GET /stores" do
+ xit "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
- get products_path
+ get stores_path
response.status.should be(200)
end
end
View
35 spec/routing/products_routing_spec.rb
@@ -1,35 +0,0 @@
-require "spec_helper"
-
-describe ProductsController do
- describe "routing" do
-
- it "routes to #index" do
- get("/products").should route_to("products#index")
- end
-
- it "routes to #new" do
- get("/products/new").should route_to("products#new")
- end
-
- it "routes to #show" do
- get("/products/1").should route_to("products#show", :id => "1")
- end
-
- it "routes to #edit" do
- get("/products/1/edit").should route_to("products#edit", :id => "1")
- end
-
- it "routes to #create" do
- post("/products").should route_to("products#create")
- end
-
- it "routes to #update" do
- put("/products/1").should route_to("products#update", :id => "1")
- end
-
- it "routes to #destroy" do
- delete("/products/1").should route_to("products#destroy", :id => "1")
- end
-
- end
-end
View
40 spec/spec_helper.rb
@@ -0,0 +1,40 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+require 'vcr'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+VCR.configure do |c|
+ c.cassette_library_dir = 'spec/vcr_cassettes'
+ c.hook_into :fakeweb
+ c.configure_rspec_metadata!
+end
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+end
View
1,688 spec/vcr_cassettes/Radar/given_a_location/should_return_a_list_of_stores_with_arduino_unos_in_stock.yml
1,688 additions, 0 deletions not shown
View
164 spec/vcr_cassettes/Store/_full_address/should_be_a_valid_address.yml
@@ -0,0 +1,164 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://maps.googleapis.com/maps/api/geocode/json?address=123+Main+Street%2C+%2C+Springfield%2C+MA+3019&language=en&sensor=false
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ accept-encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ accept:
+ - ! '*/*'
+ user-agent:
+ - Ruby
+ connection:
+ - close
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ content-type:
+ - application/json; charset=UTF-8
+ date:
+ - Sun, 08 Apr 2012 15:50:41 GMT
+ expires:
+ - Mon, 09 Apr 2012 15:50:41 GMT
+ cache-control:
+ - public, max-age=86400
+ server:
+ - mafe
+ x-xss-protection:
+ - 1; mode=block
+ x-frame-options:
+ - SAMEORIGIN
+ connection:
+ - close
+ body:
+ encoding: US-ASCII
+ string: ! "{\n \"results\" : [\n {\n \"address_components\" :
+ [\n {\n \"long_name\" : \"123\",\n \"short_name\"
+ : \"123\",\n \"types\" : [ \"street_number\" ]\n },\n
+ \ {\n \"long_name\" : \"Main St\",\n \"short_name\"
+ : \"Main St\",\n \"types\" : [ \"route\" ]\n },\n
+ \ {\n \"long_name\" : \"Forest Park\",\n \"short_name\"
+ : \"Forest Park\",\n \"types\" : [ \"neighborhood\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"Springfield\",\n
+ \ \"short_name\" : \"Springfield\",\n \"types\"
+ : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"Hampden\",\n \"short_name\" : \"Hampden\",\n \"types\"
+ : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n
+ \ \"long_name\" : \"Massachusetts\",\n \"short_name\"
+ : \"MA\",\n \"types\" : [ \"administrative_area_level_1\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"United
+ States\",\n \"short_name\" : \"US\",\n \"types\"
+ : [ \"country\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"01108\",\n \"short_name\" : \"01108\",\n \"types\"
+ : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\"
+ : \"123 Main St, Springfield, MA 01108, USA\",\n \"geometry\" : {\n
+ \ \"bounds\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.08839380,\n \"lng\" : -72.57849849999999\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.08838880,\n
+ \ \"lng\" : -72.57852029999999\n }\n },\n
+ \ \"location\" : {\n \"lat\" : 42.08838880,\n \"lng\"
+ : -72.57849849999999\n },\n \"location_type\" : \"RANGE_INTERPOLATED\",\n
+ \ \"viewport\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.08974028029149,\n \"lng\" : -72.57716041970848\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.08704231970849,\n
+ \ \"lng\" : -72.57985838029150\n }\n }\n
+ \ },\n \"partial_match\" : true,\n \"types\" : [ \"street_address\"
+ ]\n },\n {\n \"address_components\" : [\n {\n
+ \ \"long_name\" : \"123\",\n \"short_name\" : \"123\",\n
+ \ \"types\" : [ \"street_number\" ]\n },\n {\n
+ \ \"long_name\" : \"Main St\",\n \"short_name\"
+ : \"Main St\",\n \"types\" : [ \"route\" ]\n },\n
+ \ {\n \"long_name\" : \"Indian Orchard\",\n \"short_name\"
+ : \"Indian Orchard\",\n \"types\" : [ \"neighborhood\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"Springfield\",\n
+ \ \"short_name\" : \"Springfield\",\n \"types\"
+ : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"Hampden\",\n \"short_name\" : \"Hampden\",\n \"types\"
+ : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n
+ \ \"long_name\" : \"Massachusetts\",\n \"short_name\"
+ : \"MA\",\n \"types\" : [ \"administrative_area_level_1\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"United
+ States\",\n \"short_name\" : \"US\",\n \"types\"
+ : [ \"country\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"01151\",\n \"short_name\" : \"01151\",\n \"types\"
+ : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\"
+ : \"123 Main St, Springfield, MA 01151, USA\",\n \"geometry\" : {\n
+ \ \"bounds\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.15979170,\n \"lng\" : -72.50460529999999\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.1597750,\n
+ \ \"lng\" : -72.50460810\n }\n },\n
+ \ \"location\" : {\n \"lat\" : 42.1597750,\n \"lng\"
+ : -72.50460810\n },\n \"location_type\" : \"RANGE_INTERPOLATED\",\n
+ \ \"viewport\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.16113233029149,\n \"lng\" : -72.50325771970849\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.15843436970850,\n
+ \ \"lng\" : -72.50595568029151\n }\n }\n
+ \ },\n \"partial_match\" : true,\n \"types\" : [ \"street_address\"
+ ]\n },\n {\n \"address_components\" : [\n {\n
+ \ \"long_name\" : \"123\",\n \"short_name\" : \"123\",\n
+ \ \"types\" : [ \"street_number\" ]\n },\n {\n
+ \ \"long_name\" : \"Main St\",\n \"short_name\"
+ : \"Main St\",\n \"types\" : [ \"route\" ]\n },\n
+ \ {\n \"long_name\" : \"Agawam\",\n \"short_name\"
+ : \"Agawam\",\n \"types\" : [ \"locality\", \"political\" ]\n
+ \ },\n {\n \"long_name\" : \"Hampden\",\n
+ \ \"short_name\" : \"Hampden\",\n \"types\" : [
+ \"administrative_area_level_2\", \"political\" ]\n },\n {\n
+ \ \"long_name\" : \"Massachusetts\",\n \"short_name\"
+ : \"MA\",\n \"types\" : [ \"administrative_area_level_1\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"United
+ States\",\n \"short_name\" : \"US\",\n \"types\"
+ : [ \"country\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"01001\",\n \"short_name\" : \"01001\",\n \"types\"
+ : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\"
+ : \"123 Main St, Agawam, MA 01001, USA\",\n \"geometry\" : {\n \"bounds\"
+ : {\n \"northeast\" : {\n \"lat\" : 42.08715630,\n
+ \ \"lng\" : -72.6227540\n },\n \"southwest\"
+ : {\n \"lat\" : 42.08714560,\n \"lng\" :
+ -72.62277150\n }\n },\n \"location\" :
+ {\n \"lat\" : 42.08715630,\n \"lng\" : -72.6227540\n
+ \ },\n \"location_type\" : \"RANGE_INTERPOLATED\",\n
+ \ \"viewport\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.08849993029150,\n \"lng\" : -72.62141376970850\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.08580196970850,\n
+ \ \"lng\" : -72.62411173029150\n }\n }\n
+ \ },\n \"partial_match\" : true,\n \"types\" : [ \"street_address\"
+ ]\n },\n {\n \"address_components\" : [\n {\n
+ \ \"long_name\" : \"123\",\n \"short_name\" : \"123\",\n
+ \ \"types\" : [ \"street_number\" ]\n },\n {\n
+ \ \"long_name\" : \"Main St\",\n \"short_name\"
+ : \"Main St\",\n \"types\" : [ \"route\" ]\n },\n
+ \ {\n \"long_name\" : \"West Springfield\",\n \"short_name\"
+ : \"West Springfield\",\n \"types\" : [ \"locality\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"Hampden\",\n
+ \ \"short_name\" : \"Hampden\",\n \"types\" : [
+ \"administrative_area_level_2\", \"political\" ]\n },\n {\n
+ \ \"long_name\" : \"Massachusetts\",\n \"short_name\"
+ : \"MA\",\n \"types\" : [ \"administrative_area_level_1\", \"political\"
+ ]\n },\n {\n \"long_name\" : \"United
+ States\",\n \"short_name\" : \"US\",\n \"types\"
+ : [ \"country\", \"political\" ]\n },\n {\n \"long_name\"
+ : \"01089\",\n \"short_name\" : \"01089\",\n \"types\"
+ : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\"
+ : \"123 Main St, West Springfield, MA 01089, USA\",\n \"geometry\"
+ : {\n \"bounds\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.10566120,\n \"lng\" : -72.6151570\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.10565070,\n
+ \ \"lng\" : -72.61516940\n }\n },\n
+ \ \"location\" : {\n \"lat\" : 42.10566120,\n \"lng\"
+ : -72.6151570\n },\n \"location_type\" : \"RANGE_INTERPOLATED\",\n
+ \ \"viewport\" : {\n \"northeast\" : {\n \"lat\"
+ : 42.10700493029150,\n \"lng\" : -72.61381421970849\n },\n
+ \ \"southwest\" : {\n \"lat\" : 42.10430696970850,\n
+ \ \"lng\" : -72.61651218029149\n }\n }\n
+ \ },\n \"partial_match\" : true,\n \"types\" : [ \"street_address\"
+ ]\n }\n ],\n \"status\" : \"OK\"\n}\n"
+ http_version: '1.1'
+ recorded_at: Sun, 08 Apr 2012 15:50:43 GMT
+recorded_with: VCR 2.0.1
View
1,359 spec/vcr_cassettes/StoresController/GET_index/assigns_float_coordinates_to_lat_and_lng.yml
1,359 additions, 0 deletions not shown
View
1,290 spec/vcr_cassettes/StoresController/GET_index/assigns_nearby_stores_to_locations.yml
1,290 additions, 0 deletions not shown
View
1,764 spec/vcr_cassettes/StoresController/GET_index/defaults_to_params_for_location.yml
1,764 additions, 0 deletions not shown
View
1,396 spec/vcr_cassettes/StoresController/GET_index/geolocates_the_user_by_ip.yml
1,396 additions, 0 deletions not shown
View
1,359 spec/vcr_cassettes/StoresController/GET_index/sets_a_default_location_for_the_user.yml
1,359 additions, 0 deletions not shown
View
1,362 spec/vcr_cassettes/StoresController/GET_index/should_render_the_proper_view.yml
1,362 additions, 0 deletions not shown
View
20 spec/views/products/edit.html.haml_spec.rb
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe "products/edit" do
- before(:each) do
- @product = assign(:product, stub_model(Product,
- :name => "MyString",
- :part_number => "MyString"
- ))
- end
-
- it "renders the edit product form" do
- render
-
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "form", :action => products_path(@product), :method => "post" do
- assert_select "input#product_name", :name => "product[name]"
- assert_select "input#product_part_number", :name => "product[part_number]"
- end
- end
-end
View
23 spec/views/products/index.html.haml_spec.rb
@@ -1,23 +0,0 @@
-require 'spec_helper'
-
-describe "products/index" do
- before(:each) do
- assign(:products, [
- stub_model(Product,
- :name => "Name",
- :part_number => "Part Number"
- ),
- stub_model(Product,
- :name => "Name",
- :part_number => "Part Number"
- )
- ])
- end
-
- it "renders a list of products" do
- render
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "tr>td", :text => "Name".to_s, :count => 2
- assert_select "tr>td", :text => "Part Number".to_s, :count => 2
- end
-end
View
20 spec/views/products/new.html.haml_spec.rb
@@ -1,20 +0,0 @@
-require 'spec_helper'
-
-describe "products/new" do
- before(:each) do
- assign(:product, stub_model(Product,
- :name => "MyString",
- :part_number => "MyString"
- ).as_new_record)
- end
-
- it "renders new product form" do
- render
-
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- assert_select "form", :action => products_path, :method => "post" do
- assert_select "input#product_name", :name => "product[name]"
- assert_select "input#product_part_number", :name => "product[part_number]"
- end
- end
-end
View
17 spec/views/products/show.html.haml_spec.rb
@@ -1,17 +0,0 @@
-require 'spec_helper'
-
-describe "products/show" do
- before(:each) do
- @product = assign(:product, stub_model(Product,
- :name => "Name",
- :part_number => "Part Number"
- ))
- end
-
- it "renders attributes in <p>" do
- render
- # Run the generator again with the --webrat flag if you want to use webrat matchers
- rendered.should match(/Name/)
- rendered.should match(/Part Number/)
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.