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: 
 
# Running tests:
 
.....
 
Finished tests in 0.416870s, 11.9942 tests/s, 55.1731 assertions/s.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
 
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
Run options: 
 
# Running tests:
 
.......E..............
 
Finished tests in 0.828136s, 26.5657 tests/s, 39.8485 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:312: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:5:in `find'
    /home/rubys/git/awdwr/edition4/work-200-32/depot/app/controllers/line_items_controller.rb:50: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:425:in `_run__4206986889029428671__process_action__1203650105411647217__callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:405:in `__run_callback'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81: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:207: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:45: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:475: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:397:in `post'
    /home/rubys/git/awdwr/edition4/work-200-32/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:55:in `assert_difference'
    /home/rubys/git/awdwr/edition4/work-200-32/depot/test/functional/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit/testcase.rb:17:in `run'
    /home/rubys/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:469:in `_run__2052125644749560261__setup__3778497284069375348__callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:405:in `__run_callback'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /home/rubys/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:919:in `block in _run_suite'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:912:in `map'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:912:in `_run_suite'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:657:in `block in _run_suites'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:655:in `each'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:655:in `_run_suites'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:867:in `_run_anything'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1060:in `run_tests'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1047:in `block in _run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1046:in `each'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1046:in `_run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:21:in `run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:774:in `run'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:366:in `block (2 levels) in autorun'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:27:in `run_once'
    /home/rubys/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/test/unit.rb:365:in `block in autorun'
 
22 tests, 33 assertions, 0 failures, 1 errors, 0 skips
 
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/home/rubys/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib" "/home/rubys/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "test/functional/**/*_test.rb" ]>

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: 
 
# Running tests:
 
.....
 
Finished tests in 0.435935s, 11.4696 tests/s, 52.7601 assertions/s.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
 
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
Run options: 
 
# Running tests:
 
......................
 
Finished tests in 0.978686s, 22.4791 tests/s, 35.7623 assertions/s.
 
22 tests, 35 assertions, 0 failures, 0 errors, 0 skips
 
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]

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