Agile Web Development with Rails, Edition 4

Agile Web Development with Rails, Edition 4

10.1 Iteration E1: Creating a Smarter Cart 9.3 Iteration D3: Adding a button

9.4 Playtime

Once again, get the tests working, and add tests for the smarter cart.

See that the tests fail.

rake test
Run options: --seed 57052
 
# Running tests:
 
.....
 
Finished tests in 0.361956s, 13.8139 tests/s, 63.5437 assertions/s.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
Run options: --seed 42330
 
# Running tests:
 
.......E..............
 
Finished tests in 0.949692s, 23.1654 tests/s, 43.1719 assertions/s.
 
  1) Error:
test_should_create_line_item(LineItemsControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Product without an ID
    /home/rubys/git/rails/activerecord/lib/active_record/relation/finder_methods.rb:309:in `find_with_ids'
    /home/rubys/git/rails/activerecord/lib/active_record/relation/finder_methods.rb:107:in `find'
    /home/rubys/git/rails/activerecord/lib/active_record/querying.rb:6:in `find'
    /home/rubys/git/awdwr/edition4/work-200-40/depot/app/controllers/line_items_controller.rb:46:in `create'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
    /home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:167:in `process_action'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action'
    /home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:374:in `_run__2299650503930360469__process_action__callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79:in `run_callbacks'
    /home/rubys/git/rails/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
    /home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:123:in `block in instrument'
    /home/rubys/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /home/rubys/git/rails/activesupport/lib/active_support/notifications.rb:123:in `instrument'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:204:in `process_action'
    /home/rubys/git/rails/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    /home/rubys/git/rails/actionpack/lib/abstract_controller/base.rb:121:in `process'
    /home/rubys/git/rails/actionpack/lib/abstract_controller/rendering.rb:44:in `process'
    /home/rubys/git/rails/actionpack/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
    /home/rubys/git/rails/actionpack/lib/action_controller/test_case.rb:472:in `process'
    /home/rubys/git/rails/actionpack/lib/action_controller/test_case.rb:49:in `process'
    /home/rubys/git/rails/actionpack/lib/action_controller/test_case.rb:392:in `post'
    /home/rubys/git/awdwr/edition4/work-200-40/depot/test/functional/line_items_controller_test.rb:21:in `block (2 levels) in <class:LineItemsControllerTest>'
    /home/rubys/git/rails/activesupport/lib/active_support/testing/assertions.rb:54:in `assert_difference'
    /home/rubys/git/awdwr/edition4/work-200-40/depot/test/functional/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:976:in `run'
    /home/rubys/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:29:in `block in run'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:424:in `_run__2106856202051205408__setup__callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:366:in `__run_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:79:in `run_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:28:in `run'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:814:in `block in _run_suite'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:807:in `map'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:807:in `_run_suite'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:797:in `block in _run_suites'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:797:in `map'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:797:in `_run_suites'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:773:in `_run_anything'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:936:in `run_tests'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:923:in `block in _run'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:922:in `each'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:922:in `_run'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:911:in `run'
    /home/rubys/.rvm/rubies/ruby-head-n34575/lib/ruby/2.0.0/minitest/unit.rb:691:in `block in autorun'
 
22 tests, 41 assertions, 0 failures, 1 errors, 0 skips
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/home/rubys/.rvm/rubies/ruby-head-n34575/b...]>

Update parameters passed as well as expected target of redirect

edit test/functional/line_items_controller_test.rb
  test "should create line_item" do
    assert_difference('LineItem.count') do
      post :create, product_id: products(:ruby).id
    end
 
    assert_redirected_to cart_path(assigns(:line_item).cart)
  end
rake test
Run options: --seed 24416
 
# Running tests:
 
.....
 
Finished tests in 0.263366s, 18.9850 tests/s, 87.3308 assertions/s.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
Run options: --seed 44555
 
# Running tests:
 
......................
 
Finished tests in 0.869806s, 25.2930 tests/s, 50.5860 assertions/s.
 
22 tests, 44 assertions, 0 failures, 0 errors, 0 skips

10.1 Iteration E1: Creating a Smarter Cart 9.3 Iteration D3: Adding a button