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
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.......
Finished in 0.351153 seconds.
 
7 tests, 25 assertions, 0 failures, 0 errors
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.......E..............
Finished in 1.029848 seconds.
 
  1) Error:
test_should_create_line_item(LineItemsControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Product without an ID
    app/controllers/line_items_controller.rb:46:in `create'
    test/functional/line_items_controller_test.rb:21:in `test_should_create_line_item'
    test/functional/line_items_controller_test.rb:20:in `test_should_create_line_item'
 
22 tests, 33 assertions, 0 failures, 1 errors
Errors running test:functionals!

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
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
.......
Finished in 0.434681 seconds.
 
7 tests, 25 assertions, 0 failures, 0 errors
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
......................
Finished in 0.823415 seconds.
 
22 tests, 35 assertions, 0 failures, 0 errors

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