Skip to content

Ampers: Alex#29

Open
brownav wants to merge 7 commits into
Ada-C9:masterfrom
brownav:master
Open

Ampers: Alex#29
brownav wants to merge 7 commits into
Ada-C9:masterfrom
brownav:master

Conversation

@brownav

@brownav brownav commented Feb 20, 2018

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 keep related classes grouped together and assist in promoting DRY principles via inheritance
What is accomplished with raise ArgumentError? Helps with debugging
Why do you think we made the .all & .find methods class methods? Why not instance methods? If they were instance methods we wouldn't be able to manipulate all instances of a class at once; class methods allows us to manipulate/search/track all instances at once without repetition.
Why does it make sense to use inheritance for the online order? Because online orders are similar to regular orders with only a few differences; it reduces code repetition.
Did the presence of automated tests change the way you thought about the problem? How? It made me more aware of creating checks and balances within methods; it also forced me to slow down and more comprehensively understand each process and how they interrelate.

@CheezItMan

Copy link
Copy Markdown

Grocery Store

What We're Looking For

Feature Feedback
Baseline
Answered comprehension questions Check
Used Git Regularly You should make more granular commits and focus on functionality added in your commit messages, rather than wave.
Wave 1
All provided tests pass Yes, but see my inline notes
Using the appropriate attr_ for instance variables Yes, but see my inline notes about OnlineOrder
Wave 2
All stubbed tests are implemented fully and pass Yes, but you're not creating Order instances where you should.
Appropriately parses the product data from CSV file in Order.all Yes, but it's not returning an array of Order instances
Used CSV library only in Order.all (not in Order.find) Check, but don't assume the order in the file
Used Order.all to get order list in Order.find Check
Wave 3
All stubbed tests are implemented fully and pass Check, but some serious problems with your testing. Very similar to Order.
Used inheritance in the initialize for online order Some of your methods you didn't need to override
Used inheritance for the total method in online order Check
Use CSV library only in OnlineOrder.all Check, but .all still has issues.
Used all to get order list in find Check
Appropriately searches for Customer orders in find_by_customer Yes, but don't assume the order in the CSV file.
Additional Notes You did a lot of work here, but there are issues, especially in your tests. Check out my inline code notes. I'm happy to answer clarifying questions.

Comment thread lib/online_order.rb
module Grocery
class OnlineOrder < Order

attr_reader :id, :products, :customer_id, :status

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 can keep the attr_reader from Order and just have here:

attr_reader :customer_id, :status

Comment thread lib/online_order.rb
end

def total
if super == 0

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!

Comment thread lib/online_order.rb
if @status == "pending" || @status == "paid"
return super
else
return ArgumentError

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 think this should be: return ArgumentError.new "Unable to add a product due to status #{@status}"

However good on you for using ArgumentError

Comment thread lib/online_order.rb
end

def self.all
@@all_online_orders = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you're only using the class variable in this method, just use a local variable

Comment thread lib/online_order.rb

def self.find(id)
if id <= self.all.length
specific_online_order = self.all[id - 1]

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 shouldn't depend on the file being sorted. If the file was changed in Excel or something...

Comment thread specs/customer_spec.rb
# Feel free to split this into multiple tests if needed
end
end
array_of_customers = Grocery::Customer.all

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be in an it block

Comment thread specs/customer_spec.rb
# TODO: Your test code here!
it "Returns accurate information about the first customer" do
array_of_customers = Grocery::Customer.all
first_customer_id = array_of_customers[0][0]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be expecting:

array_of_customers[0].must_be_instance_of Order
array_of_customers[0].id.must_equal 1

etc

Instead your test code is expecting Customer.all to return an array of arrays. It should return an array of Customer objects.

This kind of thing applies for all your tests.

Comment thread specs/customer_spec.rb
it "Can find the first customer from the CSV" do
first_customer_info = Grocery::Customer.find(1)

first_customer_info.must_equal Grocery::Customer.all[0]

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 shouldn't test find against all since one depends on the other (circular testing).

Instead you should

first_customer = Grocery::Customer.find(1)
first_customer.id.must_equal 1
first_customer.email.must_equal .....

describe "#add_product" do
it "Does not permit action for processing, shipped or completed statuses" do
# TODO: Your test code here!
assert_raises ArgumentError do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To do this spec-style you can:

proc {
  @online_order.add_product
}.must_raise ArgumentError

array_of_orders = Grocery::OnlineOrder.all

array_of_orders.must_be_kind_of Array
array_of_orders.length.must_equal 100

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 to see if everything is an OnlineOrder.

array_of_orders.all? do |order|
  order.class == Grocery::OnlineOrder
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