-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caroline, Analisa, Wini, and Wenji - Betsy - Octos #28
base: master
Are you sure you want to change the base?
Conversation
…ucts, Reviews, and Categories
…der portion. Implementing Image Orbit
…acon grease. Unpredictable and messy. Switching to finish Reviews Controller methods new and create
…ests are not passing. Need another set of eyes on it. Still working on homepage
… one, and if there was no cart session to create a ner cart
… not created tests for them yet. Created view helper for displaying prices and totals in dollars
…o links so that the orbital reloads upon redirect
…e or two more to add in. Wish me luck
… to test if we want
…status methods. Completed merchant model testing.
bEtsyWhat We're Looking For
Only the person who submitted the PR will get an email about this feedback. Please let the rest of your team know about it. |
|
||
get 'products/by_name', to: 'products#by_name', as: 'product_by_name' | ||
resources :products, only: [:index, :edit, :show, :new, :create, :update] | ||
resources :products, only: [:index, :show] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have resources :products
twice here?
patch "/my_orders/:id/change_status" , to: "orders#change_status", as: "change_status" | ||
|
||
get "/merchants/:id/show_products", to: "merchants#show_products", as: "show_products" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is line 26 different from the display
route above on line 10?
|
||
resources :merchants do | ||
resources :categories, only: [:index, :new, :create, :show] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the category routes need to be nested here?
get 'merchants/by_name', to: 'merchants#by_name', as: 'merchant_by_name' | ||
resources :merchants do | ||
resources :products, only: [ :new, :create, :edit, :update] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these product
routes should probably be nested. For new
and create
you should take the merchant ID from the session, rather than requiring the user to have it in the route, and for edit
and update
you can get the merchant ID from the product ID (making sure to check it against the one currently in the session).
end | ||
|
||
patch "/products/retire/:id", to: "products#retire", as: "retire" | ||
get "/merchants/:merchant_id/display-products", to: "merchants#display", as: "display" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 9 should probably be /products/:id/retire
it "renders forbidden and does not update the DB when product belongs to the merchant" do | ||
product = Product.first | ||
merchant = product.merchant | ||
login(merchant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you're logged in as someone other than the seller of this product?
if @order.save | ||
@cart.cartitems.each do |cartitem| | ||
product = Product.find(cartitem.product_id) | ||
product.stock = product.new_stock(cartitem.quantity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this work should probably be in a model method on Order
.
|
||
flash.now[:status] = :failure | ||
flash.now[:result_text] = "Could not place your order" | ||
flash.now[:messages] = @order.errors.messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many places in this app where you have code similar to this, setting the status to :failure
and adding :result_text
and :messages
. Could you make this a helper method in the ApplicationController
, something along the lines of:
def report_failure(result_text, model=nil, current_request: true)
target = current_request ? flash.now : flash
target[:status] = :failure
target[:result_text] = result_text
if model
target[:messages] = model.errors.messages
end
end
Then here you could call it with report_failure("Could not place your order", @order)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea!
before_action :find_order, only: [:update, :edit, :show, :my_order, :change_status] | ||
|
||
before_action :find_cart_by_session, only: [:new] | ||
before_action :find_cart_by_order, only: [:update, :show] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of filters to keep this controller DRY.
def create | ||
if session[:cart_id] | ||
@cart = Cart.find_by(id: session[:cart_id]) | ||
@cartitem = Cartitem.new(cartitem_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not very DRY. I would try and separate the cart creation logic out, something like this:
def create
@cart = Cart.find_by(id: session[:cart_id])
unless @cart
# Create the cart or return an error
end
# If we get to this point then we definitely have a cart
# stored in @cart
@cartitem = @cart.cartitems.new(...)
# Save the cartitem or return an error...
end
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