Skip to content

Tor Shimizu - GroceryStore - Octos#42

Open
torshimizu wants to merge 23 commits into
Ada-C9:masterfrom
torshimizu:master
Open

Tor Shimizu - GroceryStore - Octos#42
torshimizu wants to merge 23 commits into
Ada-C9:masterfrom
torshimizu:master

Conversation

@torshimizu

Copy link
Copy Markdown

Grocery Store

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Response
Why is it useful to put classes inside modules? To namespace in the event of having a class or method that is an innate ruby class or method. Also, to keep similar ideas grouped.
What is accomplished with raise ArgumentError? Tell the user/program why your program did not work as expected
Why do you think we made the .all & .find methods class methods? Why not instance methods? .all and .find are not necessarily actions for a specific instance, but for the class as a whole.
Why does it make sense to use inheritance for the online order? Online orders have similar properties (attributes and methods) to orders.
Did the presence of automated tests change the way you thought about the problem? How? Yes! The tests made me consider why I was writing the code I was writing.

@droberts-sea

Copy link
Copy Markdown

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 yes
Wave 3
All stubbed tests are implemented fully and pass yes
Used inheritance in the initialize for online order no - see inline comment
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 yes
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!

Comment thread lib/order.rb
class Order
attr_reader :id, :products
attr_reader :id
attr_accessor :products

Copy link
Copy Markdown

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 this an attr_accessor instead of an attr_reader. As far as I can tell, you don't set the value of @products 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.products = products (using = instead of ==), ruby will give you a big error instead of doing the wrong thing.

Comment thread lib/order.rb
products_split = order[1].split(';') # products_split - array of "product:price"
products_split.each do |mash|
split = mash.split(':')
products_hash[split[0]] = split[1].to_f

Copy link
Copy Markdown

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

Comment thread specs/order_spec.rb
describe "Order.all" do
it "Returns an array of all orders" do
# TODO: Your test code here!
Grocery::Order.all.class.must_equal Array

Copy link
Copy Markdown

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 = Grocery::Order.all
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

Comment thread specs/order_spec.rb
first_item_id = 1
first_product_hash = {"Slivered Almonds"=>22.88, "Wholewheat flour" => 1.93, "Grape Seed Oil" => 74.9}
Grocery::Order.all.first.id.must_equal first_item_id
Grocery::Order.all.first.products.must_equal first_product_hash

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than calling .all several times, best practice is to call it once, save the result in a variable, and then write your expectations against that variable.

The reason why is that loading a file from disk is extremely expensive - hundreds of thousands or millions of times slower than reading from RAM. It doesn't make a big difference yet, but once you start building large pieces of software with large test suites, little changes like this start making a big difference.

See https://gist.github.com/jboner/2841832 for a little more on this.

Comment thread lib/online_order.rb
total = total.round(2)
return total
else
return total = 0.00

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On line 28, you don't need to set the local variable total, since as soon as you return from this method it's gone.

Comment thread lib/online_order.rb
def initialize(order_id, products, cust_id, fill_status)
@id = order_id.to_i
@products = products
@customer_id = cust_id.to_i

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of saving @id and @products yourself here, you should call super(order_id, products) and have Order do it for you.

Comment thread lib/online_order.rb
return nil
else
super()
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice use of super here.

Comment thread lib/online_order.rb
end

#self.find is inherited from the parent class(Order)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good!

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