Skip to content

Conversation

@mgraonic
Copy link

Grocery Store

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Response
Why is it useful to put classes inside modules? To group together related classes and methods without running into naming collisions.
What is accomplished with raise ArgumentError? We were told not to do this for the grocery-store exercise. Generally an argument error is raised when attempting to pass an incorrect number of arguments or pass an incorrect argument data type.
Why do you think we made the .all & .find methods class methods? Why not instance methods? Needed to access a piece of information (attribute) across all classes, not just from a single instance.
Why does it make sense to use inheritance for the online order? The online order will have a lot of the same behavior so it's not necessary to retype that code. I'm sure there are some efficiency considerations as well.
Did the presence of automated tests change the way you thought about the problem? How? Yes, but I felt very clueless about how to write the test (when/how to instantiate an object or objects to be tested, how to write meaningful tests that account for nominal and edge cases, etc.

@mgraonic
Copy link
Author

I wasn't sure how the self.all and self.find methods were supposed to interact. Should the self.find method traverse the CSV file itself instead of the array created by self.all?

@droberts-sea
Copy link

Grocery Store

What We're Looking For

Feature Feedback
Baseline
Answered comprehension questions yes
Used Git Regularly yes
Wave 1
All provided tests pass yes
Using the appropriate attr_ for instance variables yes
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 no - see inline
Wave 3
All stubbed tests are implemented fully and pass yes
Used inheritance in the initialize for online order yes
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 no
Appropriately searches for Customer orders in find_by_customer yes
Additional Notes

Great job overall! This code is clean and well-organized. I've left some inline comments below for you to review, but in general I am happy wth this submission.

Regarding tests, your tests on this project look good to me, but if you want a little more guidance, remember that Arrange, Act, Assert pattern we talked about in class.

  1. Arrange things to your liking
    • Set initial values
    • Create an instance of the class you're testing
    • Calculate expected results
    • Do any other setup
  2. Act
    • Call the method you're currently testing
  3. Assert
    • Write expectations to ensure things came out the way you wanted

Remember also that you don't need to nail all your test cases the first time - every time you fix a bug or stumble over some bad behavior is an opportunity to write another test. This is certainly a skill that takes practice to get comfortable with. Keep up the hard work!

return order
end
end
return "ERROR: order does not exist"

Choose a reason for hiding this comment

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

Is it really an error if the order doesn't exist? A more friendly strategy might be to return nil, and let whoever called the method check for that value.

def self.find(id)
# finds an order in the collection of Order instances
@@orders.each do |order|
if order.id == id

Choose a reason for hiding this comment

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

Referencing @@orders here means that .all must be called before .find. This is a dependency that we can avoid!

Instead of saying @@orders.each do, you could say self.all.each do. This will call the all method, which will read the orders from the file if that hasn't happened yet.

This is an example of what Metz is talking about in chapter 2 when she says "depend on behavior, not data".


semicolon_split.each do |string|
key_value_split = string.split(':')
products[key_value_split[0]] = key_value_split[1].to_f

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 logic sorted out.

attr_reader :id, :products

FILE_NAME = "support/orders.csv"

Choose a reason for hiding this comment

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

Good use of a constant here!

describe "Order Wave 2" do
before do
@all_orders = Grocery::Order.all
# @orders = Grocery::Order

Choose a reason for hiding this comment

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

Calling Order.all here masks that dependency between .find and .all that I discussed above.

# TODO: Your test code here!
@all_online_orders.each do |order|
order.must_be_kind_of Grocery::Order
end

Choose a reason for hiding this comment

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

Shouldn't this be order.must_be_kind_of Grocery::OnlineOrder?

The reason this test passes is because an OnlineOrder is a kind of Order.


def initialize(id, products, customer_id, status = :pending)
super(id, products)
@customer_id = customer_id

Choose a reason for hiding this comment

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

Good use of super here

return nil
else
@products[product_name] = product_price
end

Choose a reason for hiding this comment

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

This misses the behavior we had with Order, where if the product was already in the order the method would return false. One way to get that behavior would be to call super here.

customer_orders << order
end
end
return customer_orders

Choose a reason for hiding this comment

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

I like that this will return an empty array if no orders match.

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