-
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 - Kimberley Zell - Hotel #22
base: master
Are you sure you want to change the base?
Conversation
… collection of rooms. Began creating tests for Booking class and created file for Booking class.
…hod to create a new reserveration under Reservations class. Need to make tests for new_reservation method
…a reservation, so that can generate list of reservations on a specific day. Added method under Reservations for list reservations by day but it is not complete yet.
… dates included in the reservation in string format - was not able to figure out how to get it to dates format directly just yet
…do not pass. Received feedback from Dan that I sould not be mixing self methods/variables and instance methods/variables. Next will adjust code to have all instance methods/variables (in Reservations class).
…ions by date method. Still does not work - not able to call method dates within the reservations class.
… this resolved the issues with Reservations method list reservations by date.
…ray. Fixed Reservations list reservations by date method. Dates must be coming through in slightly different format. Found work around to verify if dates in reservation match with date passed in.
…alidate dates. Added that method to initialize for Booking. Wrote tests for check if invalid dates raise Invalid DateError. Tests are not passing and I'm not sure why.
…tion and method to auto-assign room number if a room not chosen when creating a new reservation. Not running correctly yet. Will write tests to try to debug
…thod. Appears auto assign room number may be working without the available method. Available method appears not to be working. Temporarily commented out most of available method so that it only returns true. Will write tests for auto assign room number and then further troubleshoot available method.
… is not available when a new reservation is being made. Started creating method to list all rooms available by date and testing. It is not passing tests yet.
…blocks called @blocks. New Blocks get added to the collection when created. Wrote tests as well.
…oms. Room collection for the block is created based on number of rooms needed and available rooms for those dates. Started a method to list blocks by dates. Goal is to add this to the availability checks so that rooms will not show as available for general bookings.
…to revamp or update the available method so that it prevents rooms from being booked if they are on the available list
…w failing. New method includes checking for rooms in blocks. Need to find out why older tests for new reservations are failing. Then need to test if it works correctly with blocks.
…k and list be available date to accomodate blocks appropriately. Added new variable to indicate whether a new reservation is for a block as well. Need to write tests and also incorporate the new methods in the new reservations and new block reservations to see if they work.
…es within Block class to store info on rooms that have been booked. Added test in Block spec to test. This is working. Also have been drafting some methods within reservations that need to be tested and arranged.
…o not think I will need this. Created tests for list blocked rooms by date method within Reservations class. Corrected the method so that it functions properly. Going through all methods in Reservations to create tests and be sure each one is working properly. Check availability by date is not working properly since I rewrote the method adding in to account for blocks, so I am looking at all methods involved to trouble shoot. Currently it does not raise arugment error when a room is not available as it should.
…ted to include room numbers to prevent accidental fails. Something wrong with Atom. Pushing now in hopes that work will not be lost.
…in the new_reservation method under Reservations Class. Otherwise it was checking the room_number of the previous reservation instead of the current one.
…n block started. Tests also started. Writing more tests and then adding more functionality.
…the room requested for booking is actually in that block, and gives an error message if it is not.
…tests - not raising argument error. Have not been able to find the problem yet.
…block reservations match the block date range.
…ation is for. Fixed method and tests for checking if a room inputed during a new block reservation is in the block, which prevents booking if the room is not part of the block. All methods currently passing tests. Just need to clean up a bit.
HotelWhat We're Looking For
|
lib/Reservations.rb
Outdated
|
||
def all_rooms | ||
@rooms_collection = [] | ||
n = 1 |
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 will recreate all the rooms from scratch every time it's called. This is a problem because any reference to a room from before won't register as equal to a room from after even if they have the same room number, because the object IDs will be different.
A better strategy might be to check if the list already exists at the beginning of this method, and if it does immediately return it.
lib/Reservations.rb
Outdated
def new_reservation(check_in, check_out, room_number = rand(1..20), room_rate = 200) | ||
dates = Hotel::DateRange.new(check_in, check_out).dates | ||
booking = Hotel::Booking.new(check_in, check_out, room_number, room_rate) | ||
if check_availability?(dates, room_number) == false |
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're only using it as a tool to get an array of dates. 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 Reservations
.
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 Reservations
class.
This would also make it much easier to test!
lib/Booking.rb
Outdated
|
||
def total_cost | ||
num_days = (@check_out - @check_in).to_i | ||
total_cost = @room_rate * num_days |
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.
Since you have this method defined here, you should not have an attr_accessor
for :total_cost
above (since this method will override the generated one).
lib/Booking.rb
Outdated
@check_in = Date.parse(check_in) | ||
@check_out = Date.parse(check_out) | ||
@date_range = DateRange.new(@check_in, @check_out) | ||
@dates = @date_range.dates |
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.
Instead of storing the check_in, check_out and dates here, it might be cleaner to only store the DateRange
instance, and anyone who needs those attributes for a booking will have to go through date_range
. That makes for a very clean separation of responsibilities: a Booking
doesn't need to know what parts a DateRange
has or how it works, it just knows that it has one.
lib/Booking.rb
Outdated
validate_dates | ||
end | ||
|
||
def validate_dates |
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 that you run this validation right in the constructor, and that you've broken it out into a separate method. It might make even more sense as a check on the DateRange
class, rather than having a Booking
be responsible for this.
specs/Reservations-specs.rb
Outdated
# end | ||
it 'must must raise argument error if room is not available' do | ||
proc{ new_reservation2 = @new_hotel.new_reservation("2018-01-01", "2018-01-04", 1) }.must_raise ArgumentError | ||
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 a good start, but I'd like to see more coverage around what date ranges will conflict with each other. Cases I'd be interested in:
- Not available:
- Same dates
- Overlaps in the front
- Overlaps in the back
- Completely contained
- Completely containing
- Available:
- Completely before
- Completely after
- Ends on the checkin date
- Starts on the checkout date
specs/Reservations-specs.rb
Outdated
end | ||
it 'must return the correct rooms available' do | ||
@new_hotel.list_rooms_available_by_date("2018-01-03")[0].room_number.must_equal 3 | ||
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.
Other cases I'd be interested in:
- What if there are no reservations? (it should return a list of all the rooms)
- Do reservations that don't overlap the date range affect the list? (they shouldn't)
- Check the boundaries of what counts as an overlap. What about a reservation that ends on the checkin date, or starts on the checkout date?
- What if there are no vacancies? (it should return an empty array)
- What if your date range spans several small reservations? (all of the rooms from those reservations should be omitted from the list)
specs/Reservations-specs.rb
Outdated
end | ||
it "must return the correct reservations" do | ||
@new_hotel.list_reservations_by_date("2017-09-21")[0].room_number.must_equal @new_booking1.room_number | ||
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're missing some test cases here - they look very similar to the ones I would like to see for listing rooms by date.
specs/Reservations-specs.rb
Outdated
it 'must return false if there are NOT any rooms available in block to be booked' do | ||
@new_block_reservation3 = @new_hotel_with_blocks1.new_reservation_in_block("2018-01-01", "2018-01-05", "Heritage", 8) | ||
@new_block_reservation4 = @new_hotel_with_blocks1.new_reservation_in_block("2018-01-01", "2018-01-05", "Heritage", 9) | ||
@new_block_reservation5 = @new_hotel_with_blocks1.new_reservation_in_block("2018-01-01", "2018-01-05", "Heritage", 5) |
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.
Good failure case!
specs/Reservations-specs.rb
Outdated
end | ||
it 'must list the correct number of rooms for a given date' do | ||
@new_hotel.list_blocked_rooms_by_date("2018-01-02").length.must_equal 5 | ||
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.
Similar missing cases as for Booking
above.
…ss and some to DateRange class.
…es in the spec_helper file and have restarted both Atom and terminal but it's still not working. Wrote additional tests under reservations_specs.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions