-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipes - Angela- Hotel #45
base: master
Are you sure you want to change the base?
Conversation
…ers passed to Room instances.
Write initialize test for DateRange class and write DateRange implimintation code. Rename Hotel class to Admin class. Stored unused work in unused-work folder for potential future use.
Made tests for reservation class' added methods. Starting to work on Admin class and tests.
…tion(date), and list_vacancies. Need to write tests for almost all the listed methods.
So specs file was not staged. Specs are written for code except list_of_rooms, add_reservation, list_reservation(date), and list_vacancies methods.
…vation functions. This commit, refactor the initialize method to take a discount and refactor total_cost method to take discount.
…able_blocked_rooms, and find_rooms_from_block. Also added method add_reservation_to_block.
…block refactor. Work on refactoring the specs for block code.
HotelWhat We're Looking For
|
lib/Block.rb
Outdated
@discount_percent = discount_percent | ||
|
||
|
||
@reservations_array2 = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called reservations_array2
? In general, if you need to put a number after a variable's name that's usually a bad sign. Moreover, you don't have a reservations_array1
that would conflict with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that instance variables in different classes (here vs Hotel
) can have the same name - that's one of the big benefits of classes, is that they keep such things separated.
lib/Admin.rb
Outdated
|
||
@blocks.each do |block| | ||
block.reservations_array2.each do |reservation| | ||
rez_by_date << reservation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this add all reservations from all blocks to the list, regardless of whether the date is included?
lib/Admin.rb
Outdated
available_rooms = list_of_rooms | ||
|
||
date_range = DateRange.new(check_in, check_out).date_range_array | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the places that you create a DateRange
, it seems like you throw away the actual DateRange
instance and only keep track of the result of calling date_range_array
. This indicates that a method might be a better choice here, one that takes a checkin and checkout date and returns an array of dates.
The other option would be to write an instance method, something like DateRange#overlap?(other)
, that takes another DateRange
and checks to see if they overlap. Then this complex bit of logic would be hidden away in DateRange
instead of sitting here in Hotel
.
As long as you've identified "manage a range of dates" as a responsibility, then it probably makes sense to do the later, and keep that responsibility out of the Hotel
class.
This would also make it much easier to test!
lib/Admin.rb
Outdated
|
||
num_rooms_to_reserve.length.times do |room_num| | ||
block.reservations_array << Hotel::Reservation.new(room_num, check_in, check_out, discount_percent: 0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of tight coupling between Hotel
and Block
. This method relies on the block having a reservations_array
, which means if that implementation ever changes this code will need to change too. Instead, it might make sense to write a reserve_room
method on the Block
class and call that here.
lib/Admin.rb
Outdated
def create_block_by_date(rooms_per_block, check_in, check_out, block_id, discount_percent: 0.0) | ||
room_num_array = self.list_vacancies(check_in, check_out).take(rooms_per_block).to_a | ||
@blocks << Hotel::Block.new(room_num_array, check_in, check_out, block_id, discount_percent: 0.0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will pass the discount_percent through correctly - did you test this?
|
||
|
||
id = 0 | ||
@admin.find_block(id).wont_be_kind_of Hotel::Block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what will it be? nil
?
specs/date_range_spec.rb
Outdated
|
||
it "Returns array of dates in range" do | ||
@date_range.date_range_array.must_be_instance_of Array | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should explicitly check that the dates are as expected.
before do | ||
|
||
@admin = Hotel::Admin.new | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of DRYing all this up with a before
block, since it's used in most of your tests.
specs/admin_spec.rb
Outdated
@admin.blocks.length.must_equal 1 | ||
|
||
# @admin.create_block_by_date(rooms_per_block, check_in, check_out, 2).total_cost.must_equal 200 | ||
# @admin.create_block_by_date(rooms_per_block, check_in, check_out, 2).wont_equal 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create multiple blocks that share the same dates? What if there are no rooms left for that date?
lib/Admin.rb
Outdated
|
||
def add_block(room_num_array, check_in, check_out, block_id, discount_percent: 0) | ||
@blocks << Hotel::Block.new(room_num_array, check_in, check_out, block_id, discount_percent: 0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is never called, in your product code or in your tests.
…ons. Logic was a bit too much for me to grasp alone. I Will ask for help. So I decided to finish writing my tests and then will go back and refactor.
…ing towards refactoring and adding more tests for all classes.
… one reservation. Refactor add_reservation_to_block method to loosely couple the Admin and Block classes. Tests write for both refactors.
Some original feedback comments were not addressed for Hotel Revisited. However, the comments I did address deepened my understanding.
…riable @date_range_array. Now we have loosely coupled classes. DateRange#overlap and DateRange#include are up and running.
…ange#date_range_array method and completely removed it.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions
Utilizing Git is something I really internalized. For this project I underutilized it and found I wanted to look at code I wrote that was no longer on my computer.
Overall, I consolidated my learning with this assignment and felt like the program could be improve. My assignment is incomplete and the portion I did complete is squirrelly and so I want to sit with someone to go over and specifics to this assignment. It would also be nice to discuss overarching strategies to improve.