Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,5 +1,5 @@
guard :minitest, bundler: false, rubygems: false do
# with Minitest::Spec
guard :minitest, bundler: false, autorun: true, rubygems: false do
# With Minitest Reporters
watch(%r{^spec/(.*)_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
Expand Down
26 changes: 26 additions & 0 deletions lib/design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
In Implementation A classes:
CartEntry
initialize two instance variables unit_price & quantity.
ShoppingCart
initialize an instance variables with an empty array.
Order
instantiate a new instance of an entry from the Shopping Cart class with instance variable cart.
SALES_TAX is a constant
Total_Price
calculating the total price of each item in the shopping cart.

Implementation B classes
CartEntry
creates a method to calculate the price of all the same items per quantity.
ShoppingCart
Adds the sum of all items purchased.
Order
instantiate an instance of ShoppingCart and calculates the total of the order with sales tax.

I think it is better to have total_price in order because if a calculation changed in shopping cart it would automatically be reflected in order.

I don't believe it does manipulate the instance variable in other classes.

If we were to add a bulk option I would add it to the price method in CartEntry as a conditional.

I think Implementation B has a single responsibility because Implementation A has some classes with zero responsibility.
116 changes: 116 additions & 0 deletions lib/front_desk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require_relative "rooms.rb"
require_relative "reservations.rb"


class Front_Desk

attr_reader :reservations, :rooms, :block_hold

def initialize
@reservations = []
@block_reservations = []
@rooms = load_rooms
end

def load_rooms
room_number = 0
rooms = []

20.times do
room_number += 1
rooms << Room.new({
:room_number => room_number
})
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this block makes more sense as a factory method inside Room.

return rooms
end

def reserve_room(room_number, start_date, end_date)
if start_date > end_date
raise StandardError.new("Checkin Date: #{start_date} must be before Checkout Date: #{end_date}")
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should be checking here to see if the start_date comes before the end date! Not having this fundamentally breaks a lot of the other code you've written!

available_rooms = available_rooms(start_date,end_date)
if !available_rooms.find { |room| room.room_number == room_number }
raise AlreadyReservedError.new("Room #{room} already has a reservation between #{start_date} and #{end_date}")
end

input = {}
input[:room_number] = room_number
input[:start_date] = start_date
input[:end_date] = end_date

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cool use of a hash to keep your code loose! Just as an FYI, keyword parameters do the same thing but keep greater clarity as to what's actually getting passed in!


new_reservation = Reservation.new(input)
@reservations << new_reservation

return new_reservation
end

#method to grab reservation by Date
def search_reserved_by_date(search_date)
search_date = Date.parse(search_date)
results = []

@reservations.each do |reservation|
if reservation.start_date <= search_date && search_date < reservation.end_date

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So, this expression in the if should probably be the return value of an instance method for the Reservation class.

results << @reservations
end
end

@block_reservations.each do |reservation|
if reservation.start_date <= search_date && search_date < reservation.end_date
results << @block_reservations
end
end

return results
end

def available_rooms(start_date,end_date)
start_date = Date.parse(start_date)
end_date = Date.parse(end_date)

list_of_rooms = @rooms.dup

@reservations.each do |reservation|
if !((start_date < reservation.start_date && end_date <= reservation.start_date) ||
(end_date > reservation.end_date && start_date >= reservation.end_date))
Comment thread
jazziesf marked this conversation as resolved.
list_of_rooms.reject! { |room| room.room_number == reservation.room_number }
end
end

@block_reservations.each do |block_room|
if !((start_date < block_room.start_date && end_date <= block_room.start_date) ||
(end_date > block_room.end_date && start_date >= block_room.end_date))
list_of_rooms.reject! { |room| room.room_number == block_room.room_number }
end
end

return list_of_rooms
end


def block_hold(start_date, end_date, number_of_rooms)
available_rooms = available_rooms(start_date,end_date)

if start_date > end_date
raise StandardError.new("Checkin Date: #{start_date} must be before Checkout Date: #{end_date}")
elsif number_of_rooms > 5
raise StandardError
end

number_of_rooms.times do |index|
input = {}
input[:room_number] = available_rooms[index].room_number
input[:start_date] = start_date
input[:end_date] = end_date

block_hold = Reservation.new(input)
@block_reservations << block_hold

end
return @block_reservations
end


end
20 changes: 20 additions & 0 deletions lib/reservations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "date"
require "pry"

class Reservation

attr_reader :room_number, :start_date, :end_date
def initialize(input)
@room_number = input[:room_number]
@start_date = Date.parse(input[:start_date])
@end_date = Date.parse(input[:end_date])
@@cost = total_cost
end

def total_cost
nights = (end_date - start_date).to_i
cost = (nights * 200)
return cost
end

end
9 changes: 9 additions & 0 deletions lib/rooms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Room

attr_reader :room_number

def initialize(input)
@room_number = input[:room_number]
end

end
7 changes: 7 additions & 0 deletions refactors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#complete wave 3 requirements
#add a block reservation class
#rethink the room class
#create more test for all classes
#add comments to the code
#create methods for invalid start and end dates
#look at major dependency from each class
87 changes: 87 additions & 0 deletions spec/front_desk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require_relative 'spec_helper'

describe "Front Desk Class" do
describe "Initializer" do

before do
@admin = Front_Desk.new
@new_reservation = @admin.reserve_room(5,('2018-02-03'),('2018-02-06'))

end

it "has a room number assisnged to the reservation" do
expect(@new_reservation.room_number).must_equal 5
end

it "totals the cost based on each night stay" do
expect(@new_reservation.total_cost).must_equal 600
end

it "return a instance of reservation" do
expect(@new_reservation).must_be_kind_of Reservation
end

it "adds a new reservation to the reservations array" do
expect(@admin.reservations).must_include(@new_reservation)
end

it "returns all reservation within that date" do
@admin.block_hold(('2018-02-03'),('2018-02-06'),2)
@admin.reserve_room(5,('2018-02-01'),('2018-02-03'))
expect(@admin.search_reserved_by_date('2018-02-05').length).must_equal 3
end

it "returns zero for date of checkout" do
@admin.block_hold(('2018-02-03'),('2018-02-06'),2)
expect(@admin.search_reserved_by_date('2018-02-06').length).must_equal 0
end

it "room is not-available" do
@admin.reserve_room(6,('2018-02-05'),('2018-02-10'))
expect {@admin.reserve_room(6,('2018-02-05'),('2018-02-10'))}.must_raise StandardError
end

it "allows a reservation to start on the same day another reservation ends" do
expect(@admin.reserve_room(5,('2018-02-06'),('2018-02-10'))).must_be_kind_of Reservation
end

it "allows a reservation to end on the same day another reservation starts" do
expect(@admin.reserve_room(5,('2018-02-01'),('2018-02-03'))).must_be_kind_of Reservation
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are missing important test cases for overlapping reservations! What if the reservation surrounds an existing reservation? What if it's completely inside another reservation?

I'm fairly certain that your code would pass the tests, but you don't ensure that confidence by doing exhaustive testing!


it "raises an error if start date after the end date" do
expect{@admin.reserve_room(6,('2018-02-05'),('2018-02-03'))}.must_raise StandardError
end


describe "block hold reservation" do

it "makes a block reservation for 1 to 5 rooms" do
expect(@admin.block_hold(('2018-02-01'),('2018-02-03'),2).length).must_equal 2
end

it "raises error if standard reservation conflicts with block reservation" do
@admin.block_hold(('2018-02-01'),('2018-02-11'),2)
expect {@admin.reserve_room(1,('2018-02-01'),('2018-02-10'))}.must_raise StandardError
end

it "raises error if block reservation exceeds maximum(5) block reservation" do
expect {@admin.block_hold(('2018-02-01'),('2018-02-11'),6)}.must_raise StandardError
end

it "raises error if block reservations conflict" do
@admin.block_hold(('2018-02-01'),('2018-02-11'),5)
@admin.block_hold(('2018-02-01'),('2018-02-11'),5)
@admin.block_hold(('2018-02-01'),('2018-02-11'),5)
@admin.block_hold(('2018-02-01'),('2018-02-11'),4)
expect {@admin.block_hold(('2018-02-01'),('2018-02-10'),2)}.must_raise StandardError
end



end
end
end
#reserve_room creates an instance of reservation
#reservation is an array
#at index 0 cost
70 changes: 70 additions & 0 deletions spec/reservation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require_relative 'spec_helper'

describe "Reservation Class" do
describe "Initializer in Reservation" do

it "loads 20 rooms" do
admin = Front_Desk.new
rooms = admin.load_rooms
expect(rooms).must_be_kind_of Array
expect(rooms.length).must_equal 20
end

it "returns an array that has instances of room" do
admin = Front_Desk.new
rooms = admin.load_rooms
rooms.each do |room|
expect(room).must_be_kind_of Room
end
end

before do
@reservation_info = {
room_number: 1,
start_date: ('2018-02-03'),
end_date: ('2018-02-05'),
}

@reservation = Reservation.new(@reservation_info)

end

it "is an instance of Reservation Class" do
expect(@reservation).must_be_kind_of Reservation
end

it "has a room number assisnged to the reservation" do
expect(@reservation.room_number).must_equal 1

end

it "totals the cost based on each night stay" do
expect(@reservation.total_cost).must_equal 400
end




#given, when, then

end
end








# describe "total calculated" do
#
# before do
# start_date = Date.parse("2018-05-25")
# end_date = Date.parse("2018-05-25")
# end
#
# it "will correctly calculate total revenue" do
#
# expect(@driver.total_revenue).must_equal ((101.65-1.65)*2)*0.8
# end
30 changes: 30 additions & 0 deletions spec/rooms_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative 'spec_helper'


# describe "Rooms class" do
# describe "Initializer in Rooms" do
#
# it "is an instance of Room Class and Number" do
# test_room = Room.new(12)
#
# expect(test_room).must_be_kind_of Room
# expect(test_room.room).must_equal 12
# end
#
# it "list all the rooms in the hotel" do
# test_all_rooms = Room.create_rooms
# expect(test_all_rooms.length).must_equal 20
# end
#
# it "list summary of rooms" do
# test_summary_of_rooms = Room.all
# expect(test_summary_of_rooms.length).must_equal 20
# expect(test_summary_of_rooms).must_be_kind_of Array
# end
#
#
# end
# end

# if !(reservation.start_date < start_date) && !(reservation.end_date <= start_date) ||
# !(reservation.start_date < end_date) && !(reservation.end_date < end_date)
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require 'minitest'
require 'simplecov'
SimpleCov.start
require 'minitest/autorun'
require 'minitest/reporters'
# Add simplecov


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

# Require_relative your lib files here!
require_relative '../lib/rooms'
require_relative '../lib/reservations'
require_relative '../lib/front_desk'