Create a migration that copies the product price into the line item, and
add_product method in the
Cart model to capture the price whenever a new line item is created. Discuss
LineItem.all.each to iterate over all of the existing line items inside your migration.
Add unit tests which add unique products and duplicate products. Note that you will need to modify the fixture to refer to products and carts by name, for example
product: ruby. Discuss
Hint: add two tests to
test/unit/cart_test.rb; in one test create a cart, add two different books to the cart, and then make assertions as to what the
cart.total_price should be. Make sure to save the LineItems that you create before making these assertions.
Check products and line items for other places where a user friendly error message would be in order. Discuss
Hint: what about a
price too high or a
image_url that is not unique? You also aren’t limited to the validates method as Rails also has a validate method that can enforce any restriction that you can express via code.
Add the ability to delete individual line items from the cart. This will require buttons on each line, and such buttons will need to be linked to the
destroy action in the
destroy action currently redirects to the
line_items_url upon completion. Is this where you want it to go? If you change this, be sure to update your unit test. Also consider adding a
:notice. If you do so, make sure that the target view displays this notice.
- V11: eric tenne [over 1 year ago]
- V11: Krishna Aradhi [about 4 years ago]
- V9: Sam Ruby [about 4 years ago]
- V8: Sam Ruby [over 5 years ago]
- V7: Sam Ruby [about 6 years ago]
- V6: Sam Ruby [about 6 years ago]
- V5: Sam Ruby [about 6 years ago]
- V4: Sam Ruby [about 6 years ago]
- V3: Andrew de Andrade [over 6 years ago]
- V2: Andrew de Andrade [over 6 years ago]