team betsii (Barbara, Kat, Chantelle, Lindsay) - edges - betsy#25
team betsii (Barbara, Kat, Chantelle, Lindsay) - edges - betsy#25elle-terch wants to merge 362 commits intoAda-C10:masterfrom
Conversation
merging category item stuff
merge with kat
…g_orders view implementation of find OrderItem's order
Merge with Kat
bEtsyBarb: Manage Orders Page for the Merchant--it used custom controller methods that I could not figure out how to test.
Lindsay: Order Items Controller + tests. I spent a ton of time implementing that controller without testing first. As a result, I couldn't get all of my tests to pass, even though the controller seemed to work both, locally and on Heroku.
Kat: I was primarily responsible for the Items controller and model and show pages. I would very much like feedback on the tests I wrote for the items controllers. There are notes of the ones I wrote and didn’t but I would love tips on how to make the tests better and what I need to improve on please thank you.
Chantelle: I divided some model methods between orderitem and item and orderscontroller (for marking a product as paid and decreasing available items) and im not sure if that was the best implementation (so basically, good object oriented design)
Only the person who submitted the PR will get an email about this feedback. Please let the rest of your team know about it. |
| <ul> | ||
| <%@current_user_items.each do |item| %> | ||
| <li><strong><%= count %>. For sale: </strong><%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%><%= link_to "(delete)", item_path(item), method: :delete, data: { confirm: "Are you sure you want to delete this product: #{item.name}? You have #{item.quantity_available} of them"} %></li> | ||
| <li><strong>Stock: </strong><%=item.quantity_available%></li> |
There was a problem hiding this comment.
Line 25 should definitely be split across multiple lines.
| <div class="customer_info"> | ||
| <h5>Customer Information:</h5> | ||
| <% order = Order.find_by(id: order_item.order_id) %> | ||
| Name: <%= order.name %><br> |
There was a problem hiding this comment.
On line 25, you should be using the activerecord relation: order = order_item.order. Or you could omit the intermediate variable entirely, and on lines 26..28 say order_item.order.name, etc.
| order_items.each do |order_item| | ||
| @pending_order_items << order_item | ||
| end | ||
| end |
There was a problem hiding this comment.
You've got a lot of repeated work in this method, either things your application is already doing, or things that Rails can do for you.
First, you're already finding the currently logged in merchant in a controller filter, saving it in the instance variable @current_user
For lines 25..28, you already have an items relation on the User model, so you could say items_sold_by_merchant = @current_user.items.
However, we could go even further. In the User model, you could add an indirect relation to order_items: has_many :order_items, through: :items. Then, to get the list of all order_items for this user, you could say @current_user.order_items
See also our textbook resource on indirect relations
Lines 30..37 don't seem to check whether the order is pending before adding it to the list. However, we could achieve this with the following:
@pending_order_items = @current_user.order_items.select do |oi|
oi.order.status == "pending"
endThe takeaway is to make sure you're familiar with the capabilities given to you by your library. We're about to leave our Rails unit, but this will be just as relevant when we work with JavaScript libraries like jQuery and React.
bEtsy
Congratulations! You're submitting your assignment! These comprehension questions should be answered by all members of your team, not by a single teammate.
Comprehension Questions