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-p374/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
.......
Finished in 0.213714 seconds.
 
7 tests, 25 assertions, 0 failures, 0 errors
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
.......E..............
Finished in 0.471912 seconds.
 
  1) Error:
test_should_create_line_item(LineItemsControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Product without an ID
    app/controllers/line_items_controller.rb:50: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

Rerun the previously failing test to verify the fix.

ruby -I test test/functional/line_items_controller_test.rb
Loaded suite test/functional/line_items_controller_test
Started
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
.......
Finished in 0.29361 seconds.
 
7 tests, 10 assertions, 0 failures, 0 errors

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