Conversation
… room to new reservation
HotelWhat We're Looking For
|
| @blocks = [] | ||
| @rooms = [] | ||
| (1..number_of_rooms).each do |number| | ||
| @rooms << Room.new(number) |
There was a problem hiding this comment.
This should be a factory method in Room.
lib/reservations.rb
Outdated
|
|
||
|
|
||
|
|
||
| def initialize(number, number_of_rooms:1, check_in:, check_out:, discount_rate: 1) |
There was a problem hiding this comment.
number is not a great name for this parameter. I'd opt for something like id_num
lib/reservations_manager.rb
Outdated
| def reserve_room(check_in, check_out, number_of_rooms: 1 ) | ||
| new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) | ||
| assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) | ||
| assigned_rooms.each do |room| |
There was a problem hiding this comment.
What happens if there aren't enough rooms?
lib/reservations_manager.rb
Outdated
| assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) | ||
| assigned_rooms.each do |room| | ||
| new_reservation.rooms << room.id | ||
| find_room(room.id).reservations << new_reservation |
There was a problem hiding this comment.
in lieu of doing these here, I would give Room and Reservation a method to make the assignment. It's a small but important piece of making your code more loosely coupled.
lib/reservations_manager.rb
Outdated
| new_reservation = Reservation.new(@reservations.length + 1, check_in: check_in, check_out: check_out) | ||
| assigned_rooms = available_rooms(check_in, check_out).last(number_of_rooms) | ||
| assigned_rooms.each do |room| | ||
| new_reservation.rooms << room.id |
There was a problem hiding this comment.
Does this work? I only see an attr_reader?
| expect(@hotel_ada.booked_reservations(@test_date)).must_be_kind_of Array | ||
| #binding.pry | ||
| expect(@hotel_ada.booked_reservations(@test_date)[0]).must_be_instance_of Hotel::Reservation | ||
| expect(@hotel_ada.booked_reservations(@test_date).length).must_equal 3 |
There was a problem hiding this comment.
What does your program do if it isn't handed a proper date?
| #binding.pry | ||
| expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23').length).must_equal 16 | ||
| expect(@hotel_ada.available_rooms('2018-08-20', '2018-08-23')[0]).must_be_kind_of Hotel::Room | ||
| #expect(@hotel_ada.available_rooms("08.23.2018", "08.25.2018")[0].id).must_equal #rooom ID |
There was a problem hiding this comment.
You should be testing to see that the code can handle different kinds of reservation date collisions here, not merely that you are getting the right data types!
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions