The Depot Application

8.5 Iteration C4: Finishing the Cart 8.3 Iteration C2: Creating a Smarter Cart

8.4 Iteration C3: Handling Errors

Expected at least 1 element matching "a[href='http://localhost:3000/store']", found 0.

Traceback:
  /home/rubys/git/awdwr/edition3/work-192-23/vendor/rails/actionpack/lib/action_controller/assertions/selector_assertions.rb:307:in `assert_select'
  /home/rubys/git/awdwr/edition3/checkdepot.rb:134:in `block in <class:DepotTest>'
edit app/controllers/store_controller.rb
  def add_to_cart
    product = Product.find(params[:id])
    @cart = find_cart
    @cart.add_product(product)
  rescue ActiveRecord::RecordNotFound
    logger.error("Attempt to access invalid product #{params[:id]}")
    flash[:notice] = "Invalid product"
    redirect_to :action => 'index'
  end
get /store/add_to_cart/wibble

ActiveRecord::StatementInvalid in StoreController#add_to_cart

Could not find table 'products'

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-192-23/depot

Application Trace | Framework Trace | Full Trace
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `block in table_structure'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `tap'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:228:in `columns'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1305:in `columns'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1313:in `columns_hash'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1612:in `find_one'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1603:in `find_from_ids'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:620:in `find'
/home/rubys/git/awdwr/edition3/work-192-23/depot/app/controllers/store_controller.rb:9:in `add_to_cart'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:1333:in `perform_action'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_with_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `block in perform_action_with_benchmark'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `block in ms'
/home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_with_benchmark'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/rescue.rb:160:in `perform_action_with_rescue'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/flash.rb:151:in `perform_action_with_flash'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:532:in `process'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_with_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:391:in `process'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:386:in `call'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:438:in `call'

Request

Parameters:

{"id"=>"wibble"}

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}
tail -99 log/development.log
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (128.9ms)
Rendered rescues/_request_and_response (0.6ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:01) [GET]
  Parameters: {"id"=>"2"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (85.9ms)
Rendered rescues/_request_and_response (0.8ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:12) [GET]
  Parameters: {"id"=>"2"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (81.5ms)
Rendered rescues/_request_and_response (2.2ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:13) [GET]
  Parameters: {"id"=>"2"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (38.2ms)
Rendered rescues/_request_and_response (0.6ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:13) [GET]
  Parameters: {"id"=>"3"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (85.5ms)
Rendered rescues/_request_and_response (0.7ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:13) [GET]
  Parameters: {"id"=>"wibble"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (88.8ms)
Rendered rescues/_request_and_response (0.6ms)
Rendering rescues/layout (internal_server_error)
 
 
Processing StoreController#add_to_cart (for 192.168.1.100 at 2012-12-17 09:12:13) [GET]
  Parameters: {"id"=>"wibble"}
 
ActiveRecord::StatementInvalid (Could not find table 'products'):
  app/controllers/store_controller.rb:9:in `add_to_cart'
  <internal:prelude>:10:in `synchronize'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
 
Rendered rescues/_trace (46.8ms)
Rendered rescues/_request_and_response (0.7ms)
Rendering rescues/layout (internal_server_error)
edit app/views/layouts/store.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>Pragprog Books Online Store</title>
  <%= stylesheet_link_tag "depot", :media => "all" %>
</head>
<body id="store">
  <div id="banner">
    <%= image_tag("logo.png") %>
    <%= @page_title || "Pragmatic Bookshelf" %>
  </div>
  <div id="columns">
    <div id="side">
      <a href="http://www....">Home</a><br />
      <a href="http://www..../faq">Questions</a><br />
      <a href="http://www..../news">News</a><br />
      <a href="http://www..../contact">Contact</a><br />
    </div>
    <div id="main">
      <% if flash[:notice] -%>
        <div id="notice"><%= flash[:notice] %></div>
      <% end -%>
 
      <%= yield :layout %>
    </div>
  </div>
</body>
</html>
edit public/stylesheets/depot.css
#notice {
  border: 2px solid red;
  padding: 1em;
  margin-bottom: 2em;
  background-color: #f0f0f0;
  font: bold smaller sans-serif;
}
get /store/add_to_cart/wibble

ActiveRecord::StatementInvalid in StoreController#add_to_cart

Could not find table 'products'

RAILS_ROOT: /home/rubys/git/awdwr/edition3/work-192-23/depot

Application Trace | Framework Trace | Full Trace
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `block in table_structure'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `tap'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:228:in `columns'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1305:in `columns'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1313:in `columns_hash'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1612:in `find_one'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:1603:in `find_from_ids'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activerecord/lib/active_record/base.rb:620:in `find'
/home/rubys/git/awdwr/edition3/work-192-23/depot/app/controllers/store_controller.rb:9:in `add_to_cart'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:1333:in `perform_action'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_with_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `block in perform_action_with_benchmark'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `block in ms'
/home/rubys/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_with_benchmark'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/rescue.rb:160:in `perform_action_with_rescue'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/flash.rb:151:in `perform_action_with_flash'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:532:in `process'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_with_filters'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:391:in `process'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/base.rb:386:in `call'
/home/rubys/git/awdwr/edition3/work-192-23/depot/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:438:in `call'

Request

Parameters:

{"id"=>"wibble"}

Show session dump

Response

Headers:

{"Cache-Control"=>"no-cache",
 "Content-Type"=>""}

8.5 Iteration C4: Finishing the Cart 8.3 Iteration C2: Creating a Smarter Cart