Permalink
Browse files

Initial checkin

  • Loading branch information...
0 parents commit 9826059636a6b5361925ad1f2f0ddf33b345c0ad @cheezy committed Feb 8, 2011
Showing with 11,872 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +32 −0 Gemfile
  3. +75 −0 Gemfile.lock
  4. +4 −0 README
  5. +7 −0 Rakefile
  6. +6 −0 app/controllers/admin_controller.rb
  7. +87 −0 app/controllers/adoptions_controller.rb
  8. +7 −0 app/controllers/agency_controller.rb
  9. +22 −0 app/controllers/application_controller.rb
  10. +91 −0 app/controllers/carts_controller.rb
  11. +94 −0 app/controllers/orders_controller.rb
  12. +85 −0 app/controllers/puppies_controller.rb
  13. +21 −0 app/controllers/sessions_controller.rb
  14. +90 −0 app/controllers/users_controller.rb
  15. +2 −0 app/helpers/admin_helper.rb
  16. +2 −0 app/helpers/adoptions_helper.rb
  17. +2 −0 app/helpers/agency_helper.rb
  18. +2 −0 app/helpers/application_helper.rb
  19. +2 −0 app/helpers/carts_helper.rb
  20. +2 −0 app/helpers/orders_helper.rb
  21. +2 −0 app/helpers/puppies_helper.rb
  22. +2 −0 app/helpers/sessions_helper.rb
  23. +2 −0 app/helpers/users_helper.rb
  24. +9 −0 app/models/adoption.rb
  25. +18 −0 app/models/cart.rb
  26. +14 −0 app/models/order.rb
  27. +21 −0 app/models/puppy.rb
  28. +48 −0 app/models/user.rb
  29. +4 −0 app/views/admin/index.html.erb
  30. +5 −0 app/views/adoptions/_adoption.html.erb
  31. +25 −0 app/views/adoptions/_form.html.erb
  32. +6 −0 app/views/adoptions/edit.html.erb
  33. +25 −0 app/views/adoptions/index.html.erb
  34. +5 −0 app/views/adoptions/new.html.erb
  35. +15 −0 app/views/adoptions/show.html.erb
  36. +18 −0 app/views/agency/index.html.erb
  37. +17 −0 app/views/carts/_form.html.erb
  38. +6 −0 app/views/carts/edit.html.erb
  39. +21 −0 app/views/carts/index.html.erb
  40. +5 −0 app/views/carts/new.html.erb
  41. +13 −0 app/views/carts/show.html.erb
  42. +38 −0 app/views/layouts/application.html.erb
  43. +34 −0 app/views/orders/_form.html.erb
  44. +6 −0 app/views/orders/edit.html.erb
  45. +30 −0 app/views/orders/index.html.erb
  46. +7 −0 app/views/orders/new.html.erb
  47. +25 −0 app/views/orders/show.html.erb
  48. +41 −0 app/views/puppies/_form.html.erb
  49. +6 −0 app/views/puppies/edit.html.erb
  50. +30 −0 app/views/puppies/index.html.erb
  51. +5 −0 app/views/puppies/new.html.erb
  52. +16 −0 app/views/puppies/show.html.erb
  53. +2 −0 app/views/sessions/create.html.erb
  54. +2 −0 app/views/sessions/destroy.html.erb
  55. +25 −0 app/views/sessions/new.html.erb
  56. +34 −0 app/views/users/_form.html.erb
  57. +6 −0 app/views/users/edit.html.erb
  58. +28 −0 app/views/users/index.html.erb
  59. +5 −0 app/views/users/new.html.erb
  60. +20 −0 app/views/users/show.html.erb
  61. +4 −0 config.ru
  62. +42 −0 config/application.rb
  63. +13 −0 config/boot.rb
  64. +22 −0 config/database.yml
  65. +5 −0 config/environment.rb
  66. +26 −0 config/environments/development.rb
  67. +49 −0 config/environments/production.rb
  68. +35 −0 config/environments/test.rb
  69. +7 −0 config/initializers/backtrace_silencers.rb
  70. +10 −0 config/initializers/inflections.rb
  71. +5 −0 config/initializers/mime_types.rb
  72. +7 −0 config/initializers/secret_token.rb
  73. +8 −0 config/initializers/session_store.rb
  74. +5 −0 config/locales/en.yml
  75. +78 −0 config/routes.rb
  76. +18 −0 db/migrate/20101017133235_create_puppies.rb
  77. +12 −0 db/migrate/20101017213458_create_carts.rb
  78. +14 −0 db/migrate/20101017223008_create_adoptions.rb
  79. +9 −0 db/migrate/20101018100440_add_quantity_to_adoption.rb
  80. +23 −0 db/migrate/20101018110302_combilne_items_in_cart.rb
  81. +16 −0 db/migrate/20101128125809_create_orders.rb
  82. +9 −0 db/migrate/20101128125854_add_order_id_to_adoption.rb
  83. +15 −0 db/migrate/20101128180606_create_users.rb
  84. +57 −0 db/schema.rb
  85. +60 −0 db/seeds.rb
  86. +2 −0 doc/README_FOR_APP
  87. 0 lib/tasks/.gitkeep
  88. +26 −0 public/404.html
  89. +26 −0 public/422.html
  90. +26 −0 public/500.html
  91. 0 public/favicon.ico
  92. BIN public/images/Brook.jpg
  93. BIN public/images/Hannah.jpg
  94. BIN public/images/MaggieMae.jpg
  95. BIN public/images/Spud.jpg
  96. BIN public/images/rails.png
  97. +2 −0 public/javascripts/application.js
  98. +965 −0 public/javascripts/controls.js
  99. +974 −0 public/javascripts/dragdrop.js
  100. +1,123 −0 public/javascripts/effects.js
  101. +6,001 −0 public/javascripts/prototype.js
  102. +175 −0 public/javascripts/rails.js
  103. +5 −0 public/robots.txt
  104. 0 public/stylesheets/.gitkeep
  105. +215 −0 public/stylesheets/puppies.css
  106. +56 −0 public/stylesheets/scaffold.css
  107. +6 −0 script/load_orders.rb
  108. +6 −0 script/rails
  109. +9 −0 test/fixtures/adoptions.yml
  110. +11 −0 test/fixtures/carts.yml
  111. +13 −0 test/fixtures/orders.yml
  112. +17 −0 test/fixtures/puppies.yml
  113. +11 −0 test/fixtures/users.yml
  114. +9 −0 test/functional/admin_controller_test.rb
  115. +49 −0 test/functional/adoptions_controller_test.rb
  116. +9 −0 test/functional/agency_controller_test.rb
  117. +49 −0 test/functional/carts_controller_test.rb
  118. +49 −0 test/functional/orders_controller_test.rb
  119. +49 −0 test/functional/puppies_controller_test.rb
  120. +19 −0 test/functional/sessions_controller_test.rb
  121. +49 −0 test/functional/users_controller_test.rb
  122. +9 −0 test/performance/browsing_test.rb
  123. +13 −0 test/test_helper.rb
  124. +8 −0 test/unit/adoption_test.rb
  125. +8 −0 test/unit/cart_test.rb
  126. +4 −0 test/unit/helpers/admin_helper_test.rb
  127. +4 −0 test/unit/helpers/adoptions_helper_test.rb
  128. +4 −0 test/unit/helpers/agency_helper_test.rb
  129. +4 −0 test/unit/helpers/carts_helper_test.rb
  130. +4 −0 test/unit/helpers/orders_helper_test.rb
  131. +4 −0 test/unit/helpers/puppies_helper_test.rb
  132. +4 −0 test/unit/helpers/sessions_helper_test.rb
  133. +4 −0 test/unit/helpers/users_helper_test.rb
  134. +8 −0 test/unit/order_test.rb
  135. +8 −0 test/unit/puppy_test.rb
  136. +8 −0 test/unit/user_test.rb
  137. 0 vendor/plugins/.gitkeep
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+gem 'will_paginate', '>=3.0pre'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
+# end
@@ -0,0 +1,75 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0)
+ actionpack (= 3.0.0)
+ mail (~> 2.2.5)
+ actionpack (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ mail (2.2.7)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.0)
+ actionmailer (= 3.0.0)
+ actionpack (= 3.0.0)
+ activerecord (= 3.0.0)
+ activeresource (= 3.0.0)
+ activesupport (= 3.0.0)
+ bundler (~> 1.0.0)
+ railties (= 3.0.0)
+ railties (3.0.0)
+ actionpack (= 3.0.0)
+ activesupport (= 3.0.0)
+ rake (>= 0.8.4)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ sqlite3-ruby (1.3.1)
+ thor (0.14.3)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+ will_paginate (3.0.pre2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rails (= 3.0.0)
+ sqlite3-ruby
+ will_paginate (>= 3.0pre)
@@ -0,0 +1,4 @@
+== Puppies example application
+
+This is an example application that I am developing to use in an ATDD course as well
+as my book.
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Puppies::Application.load_tasks
@@ -0,0 +1,6 @@
+class AdminController < ApplicationController
+ def index
+ @total_orders = Order.count
+ end
+
+end
@@ -0,0 +1,87 @@
+class AdoptionsController < ApplicationController
+ skip_before_filter :authorize
+
+ # GET /adoptions
+ # GET /adoptions.xml
+ def index
+ @adoptions = Adoption.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @adoptions }
+ end
+ end
+
+ # GET /adoptions/1
+ # GET /adoptions/1.xml
+ def show
+ @adoption = Adoption.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @adoption }
+ end
+ end
+
+ # GET /adoptions/new
+ # GET /adoptions/new.xml
+ def new
+ @adoption = Adoption.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @adoption }
+ end
+ end
+
+ # GET /adoptions/1/edit
+ def edit
+ @adoption = Adoption.find(params[:id])
+ end
+
+ # POST /adoptions
+ # POST /adoptions.xml
+ def create
+ @cart = current_cart
+ puppy = Puppy.find(params[:puppy_id])
+ @adoption = @cart.add_puppy(puppy.id)
+
+ respond_to do |format|
+ if @adoption.save
+ format.html { redirect_to(@adoption.cart) }
+ format.xml { render :xml => @adoption, :status => :created, :location => @adoption }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @adoption.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /adoptions/1
+ # PUT /adoptions/1.xml
+ def update
+ @adoption = Adoption.find(params[:id])
+
+ respond_to do |format|
+ if @adoption.update_attributes(params[:adoption])
+ format.html { redirect_to(@adoption, :notice => 'Adoption was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @adoption.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /adoptions/1
+ # DELETE /adoptions/1.xml
+ def destroy
+ @adoption = Adoption.find(params[:id])
+ @adoption.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(adoptions_url) }
+ format.xml { head :ok }
+ end
+ end
+end
@@ -0,0 +1,7 @@
+class AgencyController < ApplicationController
+ skip_before_filter :authorize
+ def index
+ @puppies = Puppy.all
+ end
+
+end
@@ -0,0 +1,22 @@
+class ApplicationController < ActionController::Base
+ before_filter :authorize
+ protect_from_forgery
+
+ private
+
+ def current_cart
+ Cart.find(session[:cart_id])
+ rescue ActiveRecord::RecordNotFound
+ cart = Cart.create
+ session[:cart_id] = cart.id
+ cart
+ end
+
+ protected
+
+ def authorize
+ unless User.find_by_id(session[:user_id])
+ redirect_to login_url, :notice => "Please log in"
+ end
+ end
+end
@@ -0,0 +1,91 @@
+class CartsController < ApplicationController
+ skip_before_filter :authorize, :only => [:show, :create, :update, :destroy]
+
+ # GET /carts
+ # GET /carts.xml
+ def index
+ @carts = Cart.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @carts }
+ end
+ end
+
+ # GET /carts/1
+ # GET /carts/1.xml
+ def show
+ begin
+ @cart = Cart.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ logger.error "Attempt to access invalid cart #{params[:id]}"
+ redirect_to agency_url, :notice => 'Invalid cart'
+ else
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @cart }
+ end
+ end
+ end
+
+ # GET /carts/new
+ # GET /carts/new.xml
+ def new
+ @cart = Cart.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @cart }
+ end
+ end
+
+ # GET /carts/1/edit
+ def edit
+ @cart = Cart.find(params[:id])
+ end
+
+ # POST /carts
+ # POST /carts.xml
+ def create
+ @cart = Cart.new(params[:cart])
+
+ respond_to do |format|
+ if @cart.save
+ format.html { redirect_to(@cart, :notice => 'Cart was successfully created.') }
+ format.xml { render :xml => @cart, :status => :created, :location => @cart }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @cart.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /carts/1
+ # PUT /carts/1.xml
+ def update
+ @cart = Cart.find(params[:id])
+
+ respond_to do |format|
+ if @cart.update_attributes(params[:cart])
+ format.html { redirect_to(@cart, :notice => 'Cart was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @cart.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /carts/1
+ # DELETE /carts/1.xml
+ def destroy
+ @cart = Cart.find(params[:id])
+ @cart.destroy
+ session[:cart_id] = nil
+
+ respond_to do |format|
+ format.html { redirect_to(agency_url, :notice => 'Your car is currently empty') }
+ format.xml { head :ok }
+ end
+ end
+end
Oops, something went wrong. Retry.

0 comments on commit 9826059

Please sign in to comment.