Skip to content

Instantly share code, notes, and snippets.

@benhawker
Created April 8, 2016 07:07
Show Gist options
  • Save benhawker/af78c0abb76b4b9b2f50f3c22b619960 to your computer and use it in GitHub Desktop.
Save benhawker/af78c0abb76b4b9b2f50f3c22b619960 to your computer and use it in GitHub Desktop.
Rails Service Class to Auto Generate Descriptions in various locales
module Rooms
class DescriptionGenerator
attr_reader :room, :locale
def initialize(room, locale="en")
@room = room
@locale = locale
end
def generate
[
elite_or_certified,
instantly_bookable,
top_pick,
top_property,
three_positive_reviews,
("<br></br>"),
t("more_about_the_property"),
rooms_type_location,
kitchen,
size_and_bedrooms,
sleeps_number_of_beds,
("<br></br>"),
t("amenities"),
wifi,
linen,
internet_tv,
aircon,
laundry,
parking,
free_cleaning,
elevator,
wheelchair_access,
pool,
gym,
doorman,
breakfast_provided,
outdoor_space,
balcony,
("<br></br>"),
t("more_information"),
cash_deposit,
paypal_deposit,
smoking_allowed,
pets_allowed,
max_guests,
neighborhood_info
].compact.join(" ").html_safe
end
private
# Shared methods
def t(key, options={})
value = I18n.t("rooms.description_generator.#{key}")
key = "#{key}.#{sample(value.keys)}" if value.is_a?(Hash)
I18n.t("rooms.description_generator.#{key}", options.merge({ locale: locale }))
end
def sample(keys)
keys.sample
end
# Translation Helpers
def room_type
@room_type ||= I18n.t("room_types.#{room.room_type.type}", locale: locale).downcase
end
def surface_unit
@surface_unit ||= I18n.t("host.rooms.amenities_etc.#{room.surface_unit}", locale: locale)
end
def destination
@destination ||= room.destination.name_translations[locale] || room.destination.name_translations["en"] unless room.destination.blank?
end
# Sentences
def elite_or_certified
if room.host.elite?
t("elite")
elsif room.host.certified?
t("certified")
end
end
def instantly_bookable
t("instant_booking") if room.instant_booking
end
def top_pick
t("top_pick") if room.top_pick
end
def top_property
t("top_property") if room.top_property?
end
def three_positive_reviews
t("three_positive_reviews", room_type: room_type) if room.feedbacks.where(rating: true).count >= 3
end
def rooms_type_location
return if destination.blank?
if room.number_of_rooms.present? && room.number_of_rooms > 0 && room.room_type.type
t("rooms_type_location", number_of_rooms: room.number_of_rooms, room_type: room_type, destination: destination)
elsif room.number_of_rooms == 0
t("studio_type_location", destination: destination)
end
end
def kitchen
t("kitchen") if room.kitchen
end
def size_and_bedrooms
if room.surface && room.surface_unit && room.number_of_rooms && room.number_of_rooms > 1
t("size_and_bedrooms", surface: room.surface, surface_unit: surface_unit, number_of_rooms: room.number_of_rooms)
elsif room.surface && room.surface_unit && room.number_of_rooms && room.number_of_rooms == 1
t("size_and_one_bedroom", surface: room.surface, surface_unit: surface_unit)
end
end
def sleeps_number_of_beds
a = t("sleeps_with_many_double_many_single_and_many_sofa_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
b = t("sleeps_with_many_double_many_single_and_one_sofa_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
c = t("sleeps_with_many_double_one_single_and_one_sofa_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
d = t("sleeps_with_many_double_one_single_and_many_sofa_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
e = t("sleeps_with_one_double_one_single_and_one_sofa_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
f = t("sleeps_with_one_double_one_single_and_many_sofa_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
g = t("sleeps_with_one_double_many_single_and_one_sofa_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
h = t("sleeps_with_one_double_many_single_and_many_sofa_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds, sofa_beds: room.number_of_sofa_beds)
i = t("sleeps_with_many_double_and_many_single_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds)
j = t("sleeps_with_many_double_and_one_single_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds)
k = t("sleeps_with_one_double_and_many_single_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds)
l = t("sleeps_with_one_double_and_one_single_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds, single_beds: room.number_of_single_beds)
m = t("sleeps_with_double_beds", max_guests: room.max_guests, double_beds: room.number_of_double_beds)
n = t("sleeps_with_one_double_bed", max_guests: room.max_guests, double_beds: room.number_of_double_beds)
o = t("sleeps", max_guests: room.max_guests)
if room.max_guests && room.number_of_double_beds && room.number_of_single_beds && room.number_of_sofa_beds
case
when room.number_of_double_beds > 1 && room.number_of_single_beds > 1 && room.number_of_sofa_beds > 1 then a
when room.number_of_double_beds > 1 && room.number_of_single_beds > 1 && room.number_of_sofa_beds == 1 then b
when room.number_of_double_beds > 1 && room.number_of_single_beds == 1 && room.number_of_sofa_beds == 1 then c
when room.number_of_double_beds > 1 && room.number_of_single_beds == 1 && room.number_of_sofa_beds > 1 then d
when room.number_of_double_beds == 1 && room.number_of_single_beds == 1 && room.number_of_sofa_beds == 1 then e
when room.number_of_double_beds == 1 && room.number_of_single_beds == 1 && room.number_of_sofa_beds > 1 then f
when room.number_of_double_beds == 1 && room.number_of_single_beds > 1 && room.number_of_sofa_beds == 1 then g
when room.number_of_double_beds == 1 && room.number_of_single_beds > 1 && room.number_of_sofa_beds > 1 then h
end
elsif room.max_guests && room.number_of_double_beds && room.number_of_single_beds
case
when room.number_of_double_beds > 1 && room.number_of_single_beds > 1 then i
when room.number_of_double_beds > 1 && room.number_of_single_beds == 1 then j
when room.number_of_double_beds == 1 && room.number_of_single_beds > 1 then k
when room.number_of_double_beds == 1 && room.number_of_single_beds == 1 then l
end
elsif room.max_guests && room.number_of_double_beds
case
when room.number_of_double_beds > 1 then m
when room.number_of_double_beds == 1 then n
end
else o
end
end
def wifi
t("wifi", room_type: room_type) if room.wifi
end
#Amenities
def linen
t("linen") if room.bed_linen_and_towels
end
def internet_tv
if room.internet
case
when room.cabletv then t("internet_and_cable_tv")
when room.tv then t("internet_and_tv")
else t("internet")
end
end
end
def aircon
t("aircon", room_type: room_type) if room.airconditioning?
end
def laundry
t("laundry", room_type: room_type) if room.laundry
end
def parking
t("parking") if room.parking
end
def free_cleaning
t("free_cleaning") if room.free_cleaning
end
def elevator
t("elevator") if room.elevator
end
def wheelchair_access
t("wheelchair") if room.wheelchairaccess
end
def pool
t("pool") if room.pool
end
def gym
t("gym") if room.gym
end
def doorman
t("doorman") if room.doorman
end
def breakfast_provided
t("breakfast_provided") if room.breakfast
end
def outdoor_space
t("outdoor_space") if room.outdoor_space
end
def balcony
t("balcony") if room.balcony?
end
#Good to Know Section
def cash_deposit
t("cash_deposit", amount: room.deposit, currency: room.deposit_currency.code) if room.deposit_type == "cash" && room.deposit.to_i > 0
end
def paypal_deposit
t("paypal_deposit", amount: room.deposit, currency: room.deposit_currency.code) if room.deposit_type == "paypal" && room.deposit.to_i > 0
end
def check_in_out
if room.check_in_hours && room.check_in_mins && room.check_out_hours && room.check_out_mins
t("check_in_out_times", check_in_hours: room.check_in_hours, check_in_mins: room.check_in_mins, check_out_hours: room.check_out_hours, check_out_mins: room.check_out_mins)
end
end
def smoking_allowed
if room.smokingallowed
t("smoking_allowed")
else
t("smoking_not_allowed")
end
end
def pets_allowed
t("pets_allowed") if room.petsallowed
end
def max_guests
t("max_guests", max_guests: room.max_guests) if room.max_guests
end
def neighborhood_info
return unless locale == "en"
return if room.destination.blank?
return if room.destination.destination_guide.nil?
return if room.destination.destination_guide.description.blank?
neighborhood_desc = []
neighborhood_desc << t("about_the_neighborhood")
neighborhood_desc << room.destination.destination_guide.description
end
end
end
_____
require 'spec_helper'
describe Rooms::DescriptionGenerator do
let(:room) { create(:room) }
let(:locale) { 'en' }
let(:generator) { Rooms::DescriptionGenerator.new(room, locale) }
describe "#generate" do
before do
allow(generator).to receive(:sample) { |keys| keys.first }
end
let(:certified_user) { create(:user, :certified) }
let(:room) {
create(:room, :visible,
user: certified_user,
instant_booking: true,
top_pick: true,
number_of_rooms: 2, neighborhood: "Chinatown",
kitchen: true,
max_guests: 5, number_of_double_beds: 2,
wifi: true,
bed_linen_and_towels: true,
internet: true,
laundry: true,
parking: true,
free_cleaning: true,
elevator: true,
wheelchairaccess: true,
pool: true,
gym: true,
breakfast: true,
outdoor_space: true,
balcony: true,
deposit: 247,
deposit_type: 'cash',
deposit_currency: Currency.from_code("USD"),
check_in_hours: "11", check_in_mins: "30", check_out_hours: "12", check_out_mins: "30",
smokingallowed: false,
petsallowed: true)
}
it "returns the correct sentence for the above conditions" do
sentence = "We are a Roomorama Certified host. Book instantly with us! \
This is a preferred choice among guests. <br></br> <br></br><strong>More About the Property</strong><br></br> \
This is a 2 bedroom apartment located in Chinatown. There is a kitchen for your convenience. \
It sleeps 5 and has 2 double/queen beds. <br></br> <br></br><strong>Amenities</strong><br></br> \
Enjoy wifi at this apartment. Bed linens and towels are provided for your stay. \
The property has Internet. This apartment is equipped with laundry facilities. There is also parking on-site. \
Cleaning of the premise is included. There is an elevator in the building. This property allows for wheelchair access. \
For your enjoyment, there is pool access at this property. For the fitness-oriented, there is gym inside the building. \
Breakfast is provided for guests for your convenience (please liaise with host directly to arrange this). \
Guests can enjoy the outdoor space of this property. There is a balcony that guests can use too. \
<br></br> <br></br><strong>More Information</strong><br></br> \
There is a 247 USD security deposit that needs to be transferred to the host in cash when you arrive. \
Please note that smoking is not allowed at this property, so if you need, please smoke only outdoors. \
This is a pet-friendly property. Please note that the max number of guests allowed at the property is 5."
room.destination.name = "Chinatown"
expect(generator.send(:generate)).to eq (sentence)
end
end
describe "#neighborhood_info" do
it "returns nil if there is no neighborhood guide" do
room.destination.destination_guide = nil
expect(generator.send(:neighborhood_info)).to eq nil
end
end
describe "#elite_or_certified" do
it "returns certified sentence if user is certified" do
certified_sentences = I18n.t('rooms.description_generator.certified').values
room.user.host_badge = "certified"
expect(generator.send(:elite_or_certified)).to be_in(certified_sentences)
end
it "returns elite sentence if user is elite" do
elite_sentences = I18n.t('rooms.description_generator.elite').values
room.user.host_badge = "elite"
expect(generator.send(:elite_or_certified)).to be_in(elite_sentences)
end
it "returns nil if host is neither elite or certified" do
expect(generator.send(:elite_or_certified)).to eq nil
end
end
describe "#instantly_bookable" do
it "returns instantly bookable sentence if room is ib" do
ib_sentences = I18n.t('rooms.description_generator.instant_booking').values
room.instant_booking = true
expect(generator.send(:instantly_bookable)).to be_in(ib_sentences)
end
it "returns nil if room is not an ib room" do
expect(generator.send(:instantly_bookable)).to eq nil
end
end
describe "#top_pick" do
it "returns top pick sentence if room is a top pick" do
top_pick_sentences = I18n.t('rooms.description_generator.top_pick').values
room.top_pick = true
expect(generator.send(:top_pick)).to be_in(top_pick_sentences)
end
it "returns nil if room is not a top pick" do
expect(generator.send(:top_pick)).to eq nil
end
end
describe "#top_property" do
it "returns top property sentence if room is a top propery" do
top_property_sentences = I18n.t('rooms.description_generator.top_property').values
room.top_property = true
expect(generator.send(:top_property)).to be_in(top_property_sentences)
end
it "returns nil if room is not a top property" do
expect(generator.send(:top_property)).to eq nil
end
end
describe "#kitchen" do
it "returns kitchen sentence if room has a kitchen" do
kitchen_sentences = I18n.t('rooms.description_generator.kitchen').values
room.kitchen = true
expect(generator.send(:kitchen)).to be_in(kitchen_sentences)
end
it "returns nil if room is not a top pick" do
expect(generator.send(:kitchen)).to eq nil
end
end
describe "#linen" do
it "returns linens sentence if room has linens" do
sentences = I18n.t('rooms.description_generator.linen').values
room.bed_linen_and_towels = true
expect(generator.send(:linen)).to be_in(sentences)
end
it "returns nil if room is not a top pick" do
expect(generator.send(:linen)).to eq nil
end
end
describe "#internet_tv" do
it "returns internet sentence if room has internet" do
sentence = "The property has Internet."
room.internet = true
expect(generator.send(:internet_tv)).to eq(sentence)
end
it "returns internet and tv sentence if room has internet & tv" do
sentence = "The property has Internet and TV."
room.internet = true
room.tv = true
expect(generator.send(:internet_tv)).to eq(sentence)
end
it "returns internet and cable tv sentence if room has internet & cable tv" do
room.internet = true
room.cabletv = true
sentence = "The property has Internet and Cable TV."
expect(generator.send(:internet_tv)).to eq(sentence)
end
it "returns nil if room does not have any of the above" do
expect(generator.send(:internet_tv)).to eq nil
end
end
describe "#aircon" do
it "returns wifi sentence if room has wifi" do
sentence = "For your comfort, the apartment has air-conditioning."
room.airconditioning = true
expect(generator.send(:aircon)).to eq(sentence)
end
it "returns nil if room does not have aircon" do
expect(generator.send(:aircon)).to eq nil
end
end
describe "#laundry" do
it "returns wifi sentence if room has wifi" do
sentence = "This apartment is equipped with laundry facilities."
room.laundry = true
expect(generator.send(:laundry)).to eq(sentence)
end
it "returns nil if room is not have laundry" do
expect(generator.send(:laundry)).to eq nil
end
end
describe "#parking" do
it "returns parking sentence if room has parking" do
sentence = "There is also parking on-site."
room.parking = true
expect(generator.send(:parking)) .to eq(sentence)
end
it "returns nil if room does not have parking" do
expect(generator.send(:parking)).to eq nil
end
end
describe "#free_cleaning" do
it "returns free_cleaning sentence if room has free cleaning" do
sentence = "Cleaning of the premise is included."
room.free_cleaning = true
expect(generator.send(:free_cleaning)).to eq (sentence)
end
it "returns nil if room does not have free cleaning" do
expect(generator.send(:free_cleaning)).to eq nil
end
end
describe "#elevator" do
it "returns elevator sentence if room has free cleaning" do
sentence = "There is an elevator in the building."
room.elevator = true
expect(generator.send(:elevator)).to eq(sentence)
end
it "returns nil if room does not have free cleaning" do
expect(generator.send(:elevator)).to eq nil
end
end
describe "#wheelchair_access" do
it "returns wheelchair sentence if room has wheelchair access" do
sentence = "This property allows for wheelchair access."
room.wheelchairaccess = true
expect(generator.send(:wheelchair_access)).to eq(sentence)
end
it "returns nil if room does not have wheelchair access" do
expect(generator.send(:wheelchair_access)).to eq nil
end
end
describe "#pool" do
it "returns pool sentence if room has pool" do
sentence = "For your enjoyment, there is pool access at this property."
room.pool = true
expect(generator.send(:pool)) .to eq (sentence)
end
it "returns nil if room does not have a pool" do
expect(generator.send(:pool)).to eq nil
end
end
describe "#gym" do
it "returns gym sentence if room has gym" do
sentence = "For the fitness-oriented, there is gym inside the building."
room.gym = true
expect(generator.send(:gym)).to eq (sentence)
end
it "returns nil if room does not have a gym" do
expect(generator.send(:gym)).to eq nil
end
end
describe "#breakfast_provided" do
it "returns breakfast_provided sentence if room has breakfast provided" do
sentence = "Breakfast is provided for guests for your convenience (please liaise with host directly to arrange this)."
room.breakfast = true
expect(generator.send(:breakfast_provided)).to eq (sentence)
end
it "returns nil if room does not have breakfast_provided" do
expect(generator.send(:breakfast_provided)).to eq nil
end
end
describe "#outdoor_space" do
it "returns outdoor_space sentence if room has outdoor_space" do
sentence = "Guests can enjoy the outdoor space of this property."
room.outdoor_space = true
expect(generator.send(:outdoor_space)) .to eq (sentence)
end
it "returns nil if room does not have an outdoor_space" do
expect(generator.send(:outdoor_space)).to eq nil
end
end
describe "#balcony" do
it "returns balcony sentence if room has balcony" do
sentence = "There is a balcony that guests can use too."
room.balcony = true
expect(generator.send(:balcony)).to eq (sentence)
end
it "returns nil if room does not have a balcony" do
expect(generator.send(:balcony)).to eq nil
end
end
describe "#cash_deposit" do
it "returns cash deposit sentence if host requires a cash deposit" do
sentence = "There is a 247 USD security deposit that needs to be transferred to the host in cash when you arrive."
room.deposit = 247
room.deposit_type = "cash"
room.deposit_currency = Currency.from_code("USD")
expect(generator.send(:cash_deposit)).to eq (sentence)
end
it "returns nil if room does not require a cash deposit" do
expect(generator.send(:cash_deposit)).to eq nil
end
end
describe "#paypal_deposit" do
let(:certified_user) { create(:user, :certified) }
it "returns paypal deposit sentence if host requires a paypal deposit" do
sentence = "There is a 247 USD security deposit that needs to be transferred to the host by Paypal before you arrive."
room.user = certified_user
room.deposit = 247
room.deposit_type = "paypal"
room.deposit_currency = Currency.from_code("USD")
expect(generator.send(:paypal_deposit)).to eq (sentence)
end
it "returns nil if room does not require a paypal deposit" do
expect(generator.send(:paypal_deposit)).to eq nil
end
end
describe "#check_in_out" do
it "returns paypal deposit sentence if host requires a paypal deposit" do
sentence = "Check in time is: 11.30, check out time is: 12.30."
room.check_in_hours = 11
room.check_in_mins = 30
room.check_out_hours = 12
room.check_out_mins = 30
expect(generator.send(:check_in_out)).to eq (sentence)
end
it "returns nil if room does have both checkin and check out times" do
expect(generator.send(:check_in_out)).to eq nil
end
end
describe "#smoking_allowed" do
it "returns smoking allowed sentence if host allows smoking" do
sentence = "Smoking is allowed at this property."
room.smokingallowed = true
expect(generator.send(:smoking_allowed)).to eq(sentence)
end
it "returns smoking not allowed sentence if host does not allow smoking" do
sentence = "Please note that smoking is not allowed at this property, so if you need, please smoke only outdoors."
room.smokingallowed = false
expect(generator.send(:smoking_allowed)).to eq(sentence)
end
end
describe "#pets_allowed" do
it "returns pets allowed sentence if host allows pets" do
sentence = "This is a pet-friendly property."
room.petsallowed = true
expect(generator.send(:pets_allowed)).to eq(sentence)
end
it "returns nil if room does not require a cash deposit" do
expect(generator.send(:pets_allowed)).to eq nil
end
end
describe "#max_guests" do
it "returns max guests sentence with 5" do
sentence = "Please note that the max number of guests allowed at the property is 5."
room.max_guests = 5
expect(generator.send(:max_guests)).to eq (sentence)
end
end
context "translations with multiple options that require interpolation" do
before do
allow(generator).to receive(:sample) { |keys| keys.first }
end
describe "#three_positive_reviews" do
context 'when the room has 3 positive reviews' do
before do
3.times do
create(:feedback, :non_external, :positive, room: room)
end
end
it "returns three_positive_reviews sentence" do
sentence = "This apartment has been very well-rated by previous guests, you will definitely enjoy your stay!"
expect(generator.send(:three_positive_reviews)).to eq(sentence)
end
end
context 'when the room does not have 3 positive reviews' do
it "returns nil" do
expect(generator.send(:three_positive_reviews)).to eq nil
end
end
end
describe "#rooms_type_location" do
let(:room) { create(:room, :visible, number_of_rooms: 2) }
it "returns rooms type location sentence if room has rooms, type & destination name" do
sentence = "This is a 2 bedroom apartment located in Chinatown."
room.destination.name = "Chinatown"
expect(generator.send(:rooms_type_location)).to eq (sentence)
end
it "returns rooms type location sentence (with city) if room has rooms, type & " do
room.destination.name = nil
expect(generator.send(:rooms_type_location)).to eq nil
end
it "returns the studio sentence with if rooms are zero" do
room.destination.name = "Chinatown"
room.number_of_rooms = 0
expect(generator.send(:rooms_type_location)).to eq "This is a studio located in Chinatown."
end
end
describe "#size_and_bedrooms" do
it "returns size and bedrooms sentence if room has surface, surface units and number of bedrooms" do
sentence = "The property is 100 Sq Meters and has 5 bedrooms."
room.surface = "100"
room.surface_unit = "metric"
room.number_of_rooms = 5
expect(generator.send(:size_and_bedrooms)).to eq (sentence)
end
it "returns size and one bedroom sentence if room has surface, surface units and 1 bedroom" do
sentence = "The property is 100 Sq Meters and has 1 bedroom."
room.surface = "100"
room.surface_unit = "metric"
room.number_of_rooms = 1
expect(generator.send(:size_and_bedrooms)).to eq (sentence)
end
it "returns nil if room does not have surface, surface units and number of bedrooms" do
expect(generator.send(:size_and_bedrooms)).to eq nil
end
end
describe "#sleeps_number_of_beds" do
let(:room) { create(:room, :visible, max_guests: 5) }
it "returns sleeps sentence if room has a max guests number" do
sentence = "It sleeps 5."
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns sleeps with double beds sentence if room has a max guests number & number of double beds" do
sentence = "It sleeps 5 and has 2 double/queen beds."
room.number_of_double_beds = 2
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns sleeps with one double bed sentence if room has a max guests number & 1 double bed" do
sentence = "It sleeps 5 and has 1 double/queen bed."
room.number_of_double_beds = 1
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns sleeps with double and single sentence if room has a max guests number, number of double beds and also single beds" do
sentence = "It sleeps 5 and has 2 double/queen beds and 2 single beds."
room.number_of_double_beds = 2
room.number_of_single_beds = 2
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns pluralized sentence if room has a max guests number, number of double beds and also single beds" do
sentence = "It sleeps 5 and has 2 double/queen beds and 1 single bed."
room.number_of_double_beds = 2
room.number_of_single_beds = 1
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns sleeps with double and single sentence if room has a max guests number, number of double beds, single beds and also sofa beds" do
sentence = "It sleeps 5 and has 2 double/queen beds, 2 single beds, 2 sofa beds."
room.number_of_double_beds = 2
room.number_of_single_beds = 2
room.number_of_sofa_beds = 2
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns correctly pluralised sentence if room has a max guests number, number of double beds, single beds and also sofa beds" do
sentence = "It sleeps 5 and has 1 double/queen bed, 1 single bed, 2 sofa beds."
room.number_of_double_beds = 1
room.number_of_single_beds = 1
room.number_of_sofa_beds = 2
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
it "returns correctly pluralised sentence if room has a max guests number, number of double beds, single beds and also sofa beds" do
sentence = "It sleeps 5 and has 2 double/queen beds, 1 single bed, 2 sofa beds."
room.number_of_double_beds = 2
room.number_of_single_beds = 1
room.number_of_sofa_beds = 2
expect(generator.send(:sleeps_number_of_beds)).to eq (sentence)
end
end
describe "#wifi" do
it "returns wifi sentence if room has wifi" do
sentence = "Enjoy wifi at this apartment."
room.wifi = true
expect(generator.send(:wifi)).to eq(sentence)
end
it "returns nil if room does not have wifi" do
expect(generator.send(:wifi)).to eq nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment