Skip to content

Conversation

@winirarrazaval
Copy link

Grocery Store

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Response
Why is it useful to put classes inside modules? Because it is easier to access information from other classes. It feels like the structure that supports my code
What is accomplished with raise ArgumentError? Is sending an error message when the information looked for does not exist. But I am not sure why is it better or different than nil.
Why do you think we made the .all & .find methods class methods? Why not instance methods? Because both of them manage information to create intances of their own class.
Why does it make sense to use inheritance for the online order? because they share many behaviours. I do not think that I used them enough do, I realized too late that I should of than it more in the OnlineOrder.rb
Did the presence of automated tests change the way you thought about the problem? How? Yes because it gave me a hint of what was I supposed to be doing and looking for.

@droberts-sea
Copy link

Grocery Store

What We're Looking For

Feature Feedback
Baseline
Answered comprehension questions yes
Used Git Regularly yes - good work
Wave 1
All provided tests pass yes
Using the appropriate attr_ for instance variables see inline
Wave 2
All stubbed tests are implemented fully and pass yes
Appropriately parses the product data from CSV file in Order.all yes
Used CSV library only in Order.all (not in Order.find) yes
Used Order.all to get order list in Order.find yes
Wave 3
All stubbed tests are implemented fully and pass yes
Used inheritance in the initialize for online order no - see inline
Used inheritance for the total method in online order yes
Use CSV library only in OnlineOrder.all yes
Used all to get order list in find yes
Appropriately searches for Customer orders in find_by_customer
Additional Notes Great job overall! Your code is for the most part clean and readable and your test coverage looks solid. There are some inline comments below that you should review, but in general I am quite pleased with this submission. Keep up the hard work!

module Grocery
class Order
attr_reader :id, :products
attr_accessor :id, :products

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you chose to make these attr_accessors instead of attr_readers. As far as I can tell, you don't set these values anywhere outside this class, nor should you given the spec.

Leaving it an attr_reader is a safety measure, so that if you accidentally do something like if order.id = 3 (using = instead of ==), ruby will give you a big error instead of doing the wrong thing.


def add_product (product_name, product_price)
if @products.keys.include?(product_name) != true
@products[product_name] = product_price

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the explicit != true in this if statement. You could instead say:

if !@products.keys.include?(product_name)
# or
unless @products.keys.include?(product_name)

products_hash = {}
order[1].split(';').each do |product|
array_product_price = product.split(":")
products_hash[array_product_price[0]] = array_product_price[1]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work getting this tricky bit of logic figured out.

attr_accessor :customer, :online_order_id, :products, :fulfillment_status

@customer = Customer.find(id)
@products = products

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're missing a line here. Adding

def initialize(online_order_id, products, id, fulfillment_status)

between lines 9 and 10 made everything work out.

order_id = order[0].to_i
products_hash = {}
id = order[2].to_i
status = order[3].to_sym

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wise to call the variable on line 24 customer_id, to make it very clear what it is.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment applies to pretty much anywhere you're using the variable id in this file.

@customer = Customer.find(id)
@products = products
@online_order_id = online_order_id
@fulfillment_status = fulfillment_status

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of saving the order id and the product list yourself, you should call super and have the initialize method for Order do that work for you.

if @fulfillment_status == (:pending || :paid )
super
else
case @fulfillment_status

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you combine the case and the if into one thing here?

array = Grocery::Order.all

array.must_be_instance_of Array

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check that the elements of the array are instances of class Order. If it gave you a bunch of strings or something like that, that would be a bug!

array.must_be_instance_of Array

# Make sure we got the right number of things from the CSV
array.length.must_equal 100

# Make sure everything has been made into an Order
array.each do |order|
  order.must_be_instance_of Grocery::Order
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants