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
[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.
[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.
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
 
ProductTest:
     PASS image url (0.22s) 
     PASS product attributes must not be empty (0.00s) 
     PASS product is not valid without a unique title (0.00s) 
     PASS product is not valid without a unique title - i18n (0.00s) 
     PASS product price must be positive (0.00s) 
 
Finished in 0.234114 seconds.
 
5 tests, 23 assertions, 0 failures, 0 errors, 0 skips
[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.
Loaded suite /home/rubys/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
 
CartsControllerTest:
     PASS should create cart (0.23s) 
     PASS should destroy cart (0.05s) 
     PASS should get edit (0.06s) 
     PASS should get index (0.01s) 
     PASS should get new (0.01s) 
     PASS should show cart (0.01s) 
     PASS should update cart (0.01s) 
 
LineItemsControllerTest:
    ERROR should create line item (0.01s) 
          ActiveRecord::RecordNotFound: Couldn't find Product without an ID
          /home/rubys/git/rails/activerecord/lib/active_record/relation/finder_methods.rb:308:in `find_with_ids'
 
     PASS should destroy line item (0.01s) 
     PASS should get edit (0.01s) 
     PASS should get index (0.01s) 
     PASS should get new (0.01s) 
     PASS should show line item (0.01s) 
     PASS should update line item (0.01s) 
 
ProductsControllerTest:
     PASS should create product (0.05s) 
     PASS should destroy product (0.01s) 
     PASS should get edit (0.01s) 
     PASS should get index (0.04s) 
     PASS should get new (0.01s) 
     PASS should show product (0.01s) 
     PASS should update product (0.01s) 
 
StoreControllerTest:
     PASS should get index (0.05s) 
 
Finished in 0.607303 seconds.
 
22 tests, 33 assertions, 0 failures, 1 errors, 0 skips
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
[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.
Loaded suite test/functional/line_items_controller_test
Started
 
LineItemsControllerTest:
     PASS should create line item (0.27s) 
     PASS should destroy line item (0.01s) 
     PASS should get edit (0.05s) 
     PASS should get index (0.01s) 
     PASS should get new (0.01s) 
     PASS should show line item (0.01s) 
     PASS should update line item (0.01s) 
 
Finished in 0.352195 seconds.
 
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips

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