small medium large xlarge

Me-new-3_pragsmall
24 Jun 2010, 19:56
Aston J (18 posts)

I’m guessing the first one isn’t applicable to this version of the book yet?

‘Create a migration that copies the product price into the line item, and modify the controller to capture the price at the time of the order.’

Also, as there is no help in the wiki, if anyone is stuck on the last one (remove individual items from the cart) here is what I did:

In views/carts/show.html.erb

Add this to the first row (‘<tr>’):

<td><%= button_to 'Remove item', item, :method => :delete, :confirm => 'Are you sure?' %></td>

Then in the line_items_controller, change the format.html line in ‘destroy’ to:

format.html { redirect_to(@line_item.cart, :notice => 'Item was successfully removed.') }

That will then remove the item and redirect back to cart. (I’m actually quite chuffed I did this without any help LOL! I know it’s probably simple for most people but I’m a rails nube!)

Generic-user-small
27 Jun 2010, 20:54
Alex V (5 posts)

How about the second question - “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.”

That doesn’t seem to be too relevant either since we already did that in earlier steps when checking for a unique title.

Samr_small_pragsmall
27 Jun 2010, 21:21
Sam Ruby (634 posts)

Create a migration that copies the product price into the line item, and modify the controller to capture the price at the time of the order.</blockquote>

Why would this not be applicable? On the top of page 73, you will see a picture which describes the model. In that picture, a Line Item has a price. If you look at your model, you will see that LineItem does not yet have a price, but you should be able to create a migration which adds this column.

For pre-existing line items, you don’t simply want to add this column with a null value. Instead, add code to the migration which copies product.price into line_item.price.

Note that you will need to modify the fixture to refer to products and carts by name, for example product: ruby.</blockquote>

On page 98 we did give a product a name, but the suggestion here is that you modify the fixture for line items to refer to products and carts by name. What I am suggesting is that you modify the generated fixture to look look like this.

Scott-bc_pragsmall
28 Jun 2010, 00:37
scott hamilton (1 post)

Nice work Aston. Especially on the redirect / notice. It would have taken me a while to figure out how to properly redirect a user.

Thanks for the clarification Sam. Unfortunately, I’m a bit slow when it comes to unit testing. Are we trying to test that the quantity of a line item = 1 when unique is unique, and duplicate product line items quantity increments?

Samr_small_pragsmall
28 Jun 2010, 12:50
Sam Ruby (634 posts)

Add two unique products and verify that the count of line items is two and the quantity in each is one.

Add two of the same product and verify that the count of line items is one and the quantity in that line item is two.

You know this test will pass as you have seen it work in the migration. The point of tests isn’t just to ensure that the function you just added works now. The point of tests is to ensure that the function is not only working but keeps working. When you get to section 11.5 on page 151, you will see an example of a change made to implement one feature breaks a function in a completely different area of the code – and that this is accurately and efficiently detected by the tests.

You must be logged in to comment