Your question is Push Code to Production. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
A Shopify merchant-app team wrote this checkout completion method for a flash-sale feature, and it's up for review the day before a big promotional drop where inventory will be tight on several SKUs.
class CheckoutService
def complete_order(cart, payment_token)
product = Product.find(cart.product_id)
if product.inventory_count > 0
product.update(inventory_count: product.inventory_count - cart.quantity)
end
charge = PaymentGateway.charge(payment_token, cart.total_price)
Order.create(
product_id: product.id,
quantity: cart.quantity,
total: cart.total_price,
charge_id: charge.id
)
OrderMailer.confirmation(cart.email).deliver_now
end
end
Would you push this code to production? Why or why not? Go through everything you'd want changed before a high-traffic, limited-inventory drop, not just the first bug you spot.