-
Notifications
You must be signed in to change notification settings - Fork 48
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
Sockets - Riyo #24
base: master
Are you sure you want to change the base?
Sockets - Riyo #24
Conversation
HotelWhat We're Looking For
|
|
||
it "raises an argument error if attempting to reserve an unavailable room" do | ||
@reservation_booker.create_new_reservation(2019, 02, 10, 2019, 02, 12) | ||
expect {@reservation_booker.create_new_reservation(2019, 02, 10, 2019, 02, 12)}.must_raise ArgumentError |
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 test had an error when I ran it.
@@ -0,0 +1,38 @@ | |||
module Hotel | |||
class AllRooms |
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 small thing to prepare for Rails, but we generally don't name a class in the plural. Since classes are meant to be instantiated, we name them in the singular, as they represent the 'bones' of one entity.
|
||
module Hotel | ||
class DateRange | ||
def self.valid_checkin_dates?(check_in_year, check_in_month, check_in_day) |
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.
For the whole of the DateRange
class, it would have been okay to pass in a Date
object instead of passing in the day, month and year. You can rely on Date
to make sure that the date is properly formatted.
return is_valid | ||
end | ||
|
||
def self.valid_checkout_dates?(check_out_year, check_out_month, check_out_day) |
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 does the same as the code above, so I'm not sure it's needed.
|
||
|
||
|
||
def available_on_these_dates?(check_in_date, check_out_date) |
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.
Nice! This is a good way to solve this problem.
attr_reader :all_reservations | ||
|
||
def initialize | ||
@all_rooms = Hotel::AllRooms.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.
It would have been OK to let ReservationBooker
and AllRooms
be the same class. The booker would have been responsible for managing the rooms and the reservations, which would create coupling, but to an acceptable degree.
return is_valid | ||
end | ||
|
||
def self.check_in_date(check_in_year, check_in_month, check_in_day) |
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.
Again, let the date class do this work for you. All you've done here is make a small wrapper.
rooms_not_reserved = available_rooms_by_date_range(check_in_year, check_in_month, check_in_day, check_out_year, check_out_month, check_out_day) | ||
room = rooms_not_reserved.sample | ||
|
||
if room.available_on_these_dates?(check_in_date, check_out_date) == 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.
This check should be taken care of if available_rooms_by_date_range
can be trusted. But a good check to put here: what if there are no rooms left?
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions
I still have a failing test and only got through Wave 2