Skip to content
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

Karis - Edges - Hotel #27

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9764369
created test file for initial set up to test guard
kimj42 Sep 4, 2018
f84bf41
created test_spec file to test guard
kimj42 Sep 4, 2018
511ead2
added awesome print, minitest/skip_dsl
kimj42 Sep 4, 2018
bb9a903
added change Dan requested
kimj42 Sep 4, 2018
8609b2a
no change, just finalizing that guardfile is good now
kimj42 Sep 4, 2018
05a329a
deleted lib/test.rb since that was just for initial set up before rea…
kimj42 Sep 4, 2018
7cfd993
created rooms in hotel method where it will load all rooms in hotel a…
kimj42 Sep 4, 2018
0a433dc
created test for rooms in hotel and it passed. checked if array is re…
kimj42 Sep 4, 2018
7dbba01
created initialize method with room number, checkin date, checkout date
kimj42 Sep 4, 2018
2b292b8
added test to see if initialize method raises argument errors and if …
kimj42 Sep 4, 2018
b15f566
created count_number_of_nights method to calculate number of nights u…
kimj42 Sep 5, 2018
00ef5ed
created test for count_number_of_nights method and it passed
kimj42 Sep 5, 2018
87edfda
created booking system class with initialize method
kimj42 Sep 6, 2018
a52808e
created tests for booking system initialize method
kimj42 Sep 6, 2018
aab529c
created rooms class but will determine if need to delete later
kimj42 Sep 6, 2018
95de6be
created file to test rooms class
kimj42 Sep 6, 2018
a032ab7
require relatived both booking system and rooms file
kimj42 Sep 6, 2018
9632394
created test for rooms in hotel method
kimj42 Sep 6, 2018
e8c00f0
created rooms in hotel method that lists all the rooms in hotel
kimj42 Sep 6, 2018
ee5555d
created reservation_date_range method to create array of all dates th…
kimj42 Sep 6, 2018
9e47d43
created 2 tests for reservation_date_range method and passed both
kimj42 Sep 6, 2018
4fa4d3b
changed instance variables as hash key/values
kimj42 Sep 6, 2018
6afd0c1
changed tests to accommodate the hash as input
kimj42 Sep 6, 2018
89ff764
created assign_room_to_booking method to assign room to the date range
kimj42 Sep 7, 2018
42bbd41
added tests to pass assigned room to booking method
kimj42 Sep 7, 2018
1b1212c
created calculate_booking_cost method to calculate cost of booking by…
kimj42 Sep 7, 2018
4bd629b
created test for calculate_booking_cost method and passed all tests
kimj42 Sep 7, 2018
c8d4d2d
made booked_dates as attr_reader to read it
kimj42 Sep 7, 2018
1e04809
created test for checking existence of booked_dates and for creating …
kimj42 Sep 7, 2018
d721fa5
deleted unnecessary file
kimj42 Sep 7, 2018
5091434
changed file name and made booking system create a new instance of re…
kimj42 Sep 7, 2018
adc40e1
created make_reservation that makes new instance of reservation withi…
kimj42 Sep 7, 2018
2417864
changed file names
kimj42 Sep 7, 2018
677185b
deleted unnecessary methods
kimj42 Sep 7, 2018
c0c9721
deleted unnecessary methods
kimj42 Sep 7, 2018
f1b9bf8
changed file name for readability
kimj42 Sep 7, 2018
53b73d6
changed file name for readability
kimj42 Sep 7, 2018
6a77f5b
created list_existing_reservations
kimj42 Sep 7, 2018
929977f
created calculate_booking_cost method
kimj42 Sep 7, 2018
e51b6f8
created test for list_existing_reservations
kimj42 Sep 7, 2018
f47355e
created test for list_existing_reservations method
kimj42 Sep 7, 2018
47864f1
added code in make reservation method for edge case of overlapping dates
kimj42 Sep 8, 2018
6a4136b
no change, removed the added room number again
kimj42 Sep 8, 2018
d1ea68c
added test for checking for edge case of overlapping dates
kimj42 Sep 8, 2018
ebafef3
raised error when unavailable date is asked to be booked
kimj42 Sep 8, 2018
1fb7714
changed code to make list_reservations_by_date method to show all boo…
kimj42 Sep 9, 2018
9fb37dd
added more test for list_reservations_by_date method and passed all
kimj42 Sep 9, 2018
cef78da
added test to check if booking is created when the checkin date is th…
kimj42 Sep 9, 2018
7ce9572
not using rooms.rb so deleted it
kimj42 Sep 10, 2018
42d4c53
added tests to reflect changes in booking_systems.rb
kimj42 Sep 10, 2018
6d99938
added tests to reflect changes in reservation.rb
kimj42 Sep 10, 2018
de76799
deleted because no longer needed
kimj42 Sep 10, 2018
6f851e3
changed file names
kimj42 Sep 10, 2018
14c15b1
changed file name, worked with Ada tutor on both booking_system and r…
kimj42 Sep 10, 2018
273eddc
added tests to reflect changes in reservation_creator.rb
kimj42 Sep 10, 2018
a79583b
submitting original
kimj42 Sep 13, 2018
c2f08f7
submitting original
kimj42 Sep 13, 2018
bb156ac
removed rooms
kimj42 Sep 13, 2018
af79d2a
able to assign new room number if room already booked for that date r…
kimj42 Sep 30, 2018
f748e4e
added tests to cover all edge cases Dan wrote in slack
kimj42 Sep 30, 2018
fc4e065
added method to show rooms available on specific date
kimj42 Sep 30, 2018
ae0e4ae
fixed all warning signs of unused assigned variables in tests
kimj42 Sep 30, 2018
9bfcbcb
final submission for wave 2 before refactoring to DRY code
kimj42 Sep 30, 2018
6aeea07
renamed reservation creator to reservation.rb
kimj42 Sep 30, 2018
53d07af
changed reservation_creator to reservation.rb
kimj42 Sep 30, 2018
e8f1196
completed all questions to design-activity.md
kimj42 Sep 30, 2018
660979a
created and wrote things to refactor in refactors.txt
kimj42 Sep 30, 2018
59bf096
reduced DRY in #make_reservation method and used show available rooms…
kimj42 Oct 1, 2018
1f4a43f
wrote what could be improved with the design in design-activity.md
kimj42 Oct 1, 2018
a1a99e0
created custom error msg and tested it yay
kimj42 Oct 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
guard :minitest, bundler: false, rubygems: false do
guard :minitest, bundler: false, autorun: false, rubygems: false do
# with Minitest::Spec
watch(%r{^spec/(.*)_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "speguc/#{m[1]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
end
1 change: 1 addition & 0 deletions lib/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

77 changes: 77 additions & 0 deletions lib/booking_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require_relative 'reservation_creator'
require 'pry'

module Hotel
class BookingSystem
attr_reader :rooms, :reservations, :dates

def initialize
@reservations = []
@rooms = [*1..20]
@dates = []
end

def make_reservation(check_in_date:, check_out_date:)
# TODO find a room that's available

room_number = get_available_room(check_in_date: check_in_date, check_out_date: check_out_date)

reservation = ReservationCreator.new(check_in_date: check_in_date, check_out_date: check_out_date, room_number: room_number)



# @dates.each do |date_with_room|
# date
# if reservation.date_range.include?(date) && reservation.room_number == room
#
# reservation.room_number += 1
# end
# binding.pry
# end
# end


@reservations << reservation

return reservation
end
Copy link

Choose a reason for hiding this comment

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

I think from a birds-eye view, this method make_reservation is set up for success. It's outline is the following:

  1. Figure out what the room number of the next available room is
  2. Make a new instance of reservation with the following info: the passed in check in date, check out date, and the room number from step 1
  3. add that reservation to the collection of reservations being recorded in this class on @reservations
  4. return that reservation

I think that the rest of the work for wave 2 is just filling in the detail for those steps, and those details will be filled in with the helper methods. I think that this method looks really good as is though.


def get_available_room(check_in_date:, check_out_date:)
return @rooms.first
Copy link

Choose a reason for hiding this comment

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

I'd love to get more insight into your thoughts here of how you wanted to continue and push this code -- feel free to add comments that include your pseudocode next time :)

end

def list_all_rooms
return @rooms
end

# def add_dates_with_rooms
#
# @reservations.each do |booking|
#
# booking.date_range.each do |date|
# date_with_room = {}
# # binding.pry
#
# date_with_room[date] = booking.room_number
# @dates << date_with_room
# end
# end
#
# return @dates
# end

def list_reservations_by_date(date)
specific_date = Date.parse("#{date}")

bookings_by_date = []
@reservations.each do |booking|
dates = booking.date_range
if dates.include?(specific_date)
bookings_by_date << booking
end
end

return bookings_by_date
end
Copy link

Choose a reason for hiding this comment

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

This method looks pretty good to me. I see the following logic:

We start with figuring out the specific_date that we'll be comparing things to, and an empty collection in bookings_by_date.

Looking through the entire collection of reservations in @reservations, for every reservation, we'll get to see look at every set of dates that each reservation holds... then we'll make a comparison: if those dates include the specific date we were looking at, then we'll add the reservation/booking to the collection bookings_by_date.

Not bad -- can't wait to see more!

end
end
26 changes: 26 additions & 0 deletions lib/reservation_creator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'date'

module Hotel
class ReservationCreator
Copy link

Choose a reason for hiding this comment

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

When I look at this class, it really feels like the attributes, state, behaviors that this class has resemble more of representing a Reservation.

If this object were a "ReservationCreator," I would imagine that its behaviors would be more about making Reservation instances, and wouldn't need a check in or check out date.

attr_reader :check_in_date, :check_out_date
attr_accessor :room_number

def initialize(input)
@check_in_date = Date.parse("#{input[:check_in_date]}")

@check_out_date = Date.parse("#{input[:check_out_date]}")
raise StandardError, "Checkout date cannot be before checkin date" unless input[:check_in_date] < input[:check_out_date]
Copy link

Choose a reason for hiding this comment

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

I like this post-fix conditional! But watch your indentation ;)

@room_number = input[:room_number].nil? ? [] : input[:room_number]
Copy link

Choose a reason for hiding this comment

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

This code says: if in the passed-in input hash, there is no value defined for the key :room_number, then the value of @room_number should be assigned to the empty array []. Otherwise it will be assigned the value of input[:room_number].

I think it makes sense that @room_number is input[:room_number] if it exists, but should it be assigned to an empty array if there was no given room number?

end

def date_range
date_range = [*check_in_date...check_out_date]
return date_range
end

def calculate_booking_cost
cost = date_range.length * 200
return cost
end
end
end
44 changes: 44 additions & 0 deletions spec/booking_system_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative 'spec_helper'

describe "BookingSystem class" do
before do
@booking = Hotel::BookingSystem.new
@reservation = @booking.make_reservation(check_in_date: 180904, check_out_date: 180907)
end

it "create BookingSystem class" do
expect(@booking).must_be_kind_of Hotel::BookingSystem
end

it "initialize method" do
expect(@booking.reservations).must_be_kind_of Array
end

it "returns array of all room numbers in hotel" do
expect(@booking.list_all_rooms).must_be_kind_of Array
expect(@booking.list_all_rooms).must_equal [*1..20]
end

it "returns array of dates" do
expect(@reservation).must_be_kind_of Hotel::ReservationCreator
expect(@reservation.date_range).must_equal [Date.parse("180904"), Date.parse("180905"), Date.parse("180906")]
end

it "returns the total cost of the booking" do
expect(@reservation.calculate_booking_cost).must_equal 600
end

it "list all bookings of that date" do
bad_reservation = @booking.make_reservation(check_in_date: 180909, check_out_date: 1809010)

expect(@booking.list_reservations_by_date(180904)).must_include @reservation
expect(@booking.list_reservations_by_date(180904)).wont_include bad_reservation
end

# it "does not assign room when room is booked for that date" do
# bad_reservation = @booking.make_reservation(check_in_date: 180904, check_out_date: 180905)
#
# expect()
#
# end
end
28 changes: 28 additions & 0 deletions spec/reservation_creator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'spec_helper'

describe "ReservationCreator class" do
before do
@reservation = Hotel::ReservationCreator.new({check_in_date: 180904, check_out_date: 180905})
end

it "initialize method" do
expect(@reservation).must_be_kind_of Hotel::ReservationCreator
expect(@reservation.check_in_date).must_be_kind_of Date
expect(@reservation.check_out_date).must_be_kind_of Date
end

it "raises ArgumentError if check out date is before check in date" do
expect{(list = Hotel::ReservationCreator.new(180904, 180903))}.must_raise StandardError
end

it "returns all dates in date range" do
expect(@reservation.date_range).must_be_kind_of Array
expect(@reservation.date_range.length).must_equal 1
expect(@reservation.date_range).must_equal [Date.parse("180904")]
end

it "returns cost of that date range" do
expect(@reservation.calculate_booking_cost).must_be_kind_of Integer
expect(@reservation.calculate_booking_cost).must_equal 200
end
end
8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'simplecov'
SimpleCov.start

require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
# Add simplecov
require 'minitest/skip_dsl'
require 'awesome_print'

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

# Require_relative your lib files here!
require_relative '../lib/reservation_creator'
require_relative '../lib/booking_system'