10.1 Iteration E1: Creating a Smarter Cart 9.3 Iteration D3: Adding a button
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.109978s, 45.4635 tests/s, 209.1320 assertions/s.
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
Run options:
# Running tests:
.......E..............
Finished tests in 0.230435s, 95.4716 tests/s, 143.2074 assertions/s.
1) Error:
LineItemsControllerTest#test_should_create_line_item:
ActiveRecord::RecordNotFound: Couldn't find Product without an ID
/home/rubys/git/rails/activerecord/lib/active_record/relation/finder_methods.rb:313: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-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__745223575960275254__process_action__620947514012559203__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:490:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/test_case.rb:54:in `process'
/home/rubys/git/rails/actionpack/lib/action_controller/test_case.rb:412:in `post'
/home/rubys/git/awdwr/edition4/work-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-32/depot/test/functional/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1265:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.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__1119407130212234506__setup__4212136240903856808__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.1.5/lib/ruby/2.1.0/minitest/unit.rb:940:in `block in _run_suite'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:933:in `map'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:933:in `_run_suite'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:663:in `block in _run_suites'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:661:in `each'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:661:in `_run_suites'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:884:in `_run_anything'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1092:in `run_tests'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1079:in `block in _run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1078:in `each'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1078:in `_run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/minitest/unit.rb:1066:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:27:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:780:in `run'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:372:in `block (2 levels) in autorun'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:33:in `run_once'
/home/rubys/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/test/unit.rb:371:in `block in autorun'
22 tests, 33 assertions, 0 failures, 1 errors, 0 skips
ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [ruby -I"lib:test" -I"/home/rubys/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/lib" "/home/rubys/.rvm/gems/ruby-2.1.5/gems/rake-10.4.2/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
Rerun the previously failing test to verify the fix.
ruby -I test test/functional/line_items_controller_test.rb
Run options:
# Running tests:
.......
Finished tests in 0.141703s, 49.3992 tests/s, 70.5702 assertions/s.
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
10.1 Iteration E1: Creating a Smarter Cart 9.3 Iteration D3: Adding a button