-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates and creating reservations tested and functional
- Loading branch information
srinjoyc
committed
Apr 3, 2018
1 parent
b060dd9
commit bcd1972
Showing
13 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ReservationMailer < ApplicationMailer | ||
layout 'mailer' | ||
default from: '[email protected]' | ||
|
||
def reservation_confirmed reservation | ||
@guest = reservation.guest | ||
@reservation = reservation | ||
@restaurant = reservation.restaurant | ||
email_with_name = %("#{@guest.name}" <#{@guest.email}>) | ||
mail(to: email_with_name, subject: "Reservation confirmed at #{@restaurant.name} ") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
<h1>Welcome to umai.com, <%= @guest.name %></h1> | ||
<p> | ||
You have successfully book a reservation on, : <%= @reservation.reservation_time %>.<br> | ||
</p> | ||
<p> | ||
Your table is: <%= @reservation.restaurant_table.name %>, with <%= @reservation.guest_count %> total guests. | ||
</p> | ||
<p>Thanks for using UMAI and have a great day!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
<h1>Welcome to example2.com, <%= @user.name %></h1> | ||
<p> | ||
You have successfully signed up to example.com, | ||
your username is: <%= @user.login %>.<br> | ||
</p> | ||
<p> | ||
To login to the site, just follow this link: <%= @url %>. | ||
</p> | ||
<p>Thanks for joining and have a great day!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
Rails.application.configure do | ||
# Settings specified here will take precedence over those in config/application.rb. | ||
config.action_controller.action_on_unpermitted_parameters = :raise | ||
config.action_mailer.smtp_settings = { | ||
:address => "smtp.gmail.com", | ||
:port => 587, | ||
:domain => "gmail.com", | ||
:user_name => "[email protected]", | ||
:password => "101ckattainor", | ||
:authentication => "plain", | ||
:enable_starttls_auto => true | ||
} | ||
# In the development environment your application's code is reloaded on | ||
# every request. This slows down response time but is perfect for development | ||
# since you don't have to restart the web server when you make code changes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
Rails.application.configure do | ||
# Settings specified here will take precedence over those in config/application.rb. | ||
config.action_controller.action_on_unpermitted_parameters = :raise | ||
config.action_mailer.smtp_settings = { | ||
:address => "smtp.gmail.com", | ||
:port => 587, | ||
:domain => "gmail.com", | ||
:user_name => "[email protected]", | ||
:password => "101ckattainor", | ||
:authentication => "plain", | ||
:enable_starttls_auto => true | ||
} | ||
# Code is not reloaded between requests. | ||
config.cache_classes = true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 8:10:00" | ||
reservation_time: "Wed, 11 Jul 2012 8:10:00 GMT" | ||
}) | ||
end | ||
|
||
|
@@ -46,10 +46,12 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00" | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00 GMT" | ||
} | ||
} | ||
post :mobile_create, params: params | ||
email = ActionMailer::Base.deliveries.last | ||
puts email | ||
expect(Reservation.count).to eq(2) | ||
end | ||
end | ||
|
@@ -63,7 +65,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 8:30:00" # same time as existing resevation | ||
reservation_time: "Wed, 11 Jul 2012 8:30:00 GMT" # same time as existing resevation | ||
} | ||
} | ||
post :mobile_create, params: params | ||
|
@@ -79,7 +81,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 14:30:00" # same time as existing resevation | ||
reservation_time: "Wed, 11 Jul 2012 14:30:00 GMT" # same time as existing resevation | ||
} | ||
} | ||
post :mobile_create, params: params | ||
|
@@ -96,7 +98,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 8, | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00" # same time as existing resevation | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00 GMT" # same time as existing resevation | ||
} | ||
} | ||
post :mobile_create, params: params | ||
|
@@ -112,7 +114,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 1, | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00" # same time as existing resevation | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00 GMT" # same time as existing resevation | ||
} | ||
} | ||
post :mobile_create, params: params | ||
|
@@ -128,7 +130,7 @@ | |
restaurant_shift_id: @shift.id, | ||
guest_id: 100, | ||
guest_count: 1, | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00" # same time as existing resevation | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00 GMT" # same time as existing resevation | ||
} | ||
} | ||
post :mobile_create, params: params | ||
|
@@ -139,6 +141,142 @@ | |
end | ||
|
||
end | ||
# UPDATE | ||
describe 'Update a reservation' do | ||
# Sample guest already in database | ||
before :example do | ||
@guest = Guest.create!({ | ||
name: 'Srinjoy', | ||
email: '[email protected]' | ||
}) | ||
@restaurant = Restaurant.create!({ | ||
name: 'Food Palace', | ||
email: '[email protected]', | ||
phone_number: '444-444-4444' | ||
}) | ||
@table = RestaurantTable.create!({ | ||
name: 'Booth 1', | ||
restaurant_id: @restaurant.id, | ||
minimum_count: 3, | ||
maximum_count: 5 | ||
}) | ||
@table_two = RestaurantTable.create!({ | ||
name: 'Booth 2', | ||
restaurant_id: @restaurant.id, | ||
minimum_count: 2, | ||
maximum_count: 6 | ||
}) | ||
@shift = RestaurantShift.create!({ | ||
name: 'Morning', | ||
restaurant_id: @restaurant.id, | ||
start_time: 8, | ||
end_time: 13 | ||
}) | ||
@shift_two = RestaurantShift.create!({ | ||
name: 'Evening', | ||
restaurant_id: @restaurant.id, | ||
start_time: 18, | ||
end_time: 22 | ||
}) | ||
@reservation = Reservation.create!({ | ||
restaurant_id: @restaurant.id, | ||
restaurant_table_id: @table.id, | ||
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 9:10:00 GMT" | ||
}) | ||
@reservation_two = Reservation.create!({ | ||
restaurant_id: @restaurant.id, | ||
restaurant_table_id: @table.id, | ||
restaurant_shift_id: @shift.id, | ||
guest_id: @guest.id, | ||
guest_count: 4, | ||
reservation_time: "Wed, 11 Jul 2012 10:15:00 GMT" | ||
}) | ||
end | ||
|
||
context 'all details are valid and no conflicting reservations during update' do | ||
it 'updates the guest count' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
guest_count: 3, | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).guest_count).to eq(3) | ||
end | ||
it 'changes the reservation time to another time in the same shift' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
reservation_time: "Wed, 11 Jul 2012 9:30:00 GMT", | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).reservation_time).to eq("Wed, 11 Jul 2012 9:30:00 GMT".to_time) | ||
end | ||
it 'changes the reservation time and shift app' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
restaurant_shift_id: @shift_two.id, | ||
reservation_time: "Wed, 11 Jul 2012 19:30:00 GMT", | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).reservation_time).to eq("Wed, 11 Jul 2012 19:30:00 GMT".to_time) | ||
end | ||
|
||
it 'changes the table to another valid, available table' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
restaurant_table_id: @table_two.id, | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).restaurant_table_id).to eq(@table_two.id) | ||
end | ||
end | ||
|
||
context 'all details are NOT valid and there ARE conflicting reservations during update' do | ||
it 'updates the guest count to past the maximum' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
guest_count: 20, | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).guest_count).to eq(4) | ||
end | ||
it 'changes the reservation time to a time not in the shift of a restaurant' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
reservation_time: "Wed, 11 Jul 2012 14:30:00 GMT", | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).reservation_time).to eq("Wed, 11 Jul 2012 9:10:00 GMT".to_time) | ||
end | ||
it 'changes the reservation time to an already booked time by another guest on the same table' do | ||
params = { | ||
id: @reservation.id, | ||
reservation: { | ||
restaurant_shift_id: @shift_two.id, | ||
reservation_time: "Wed, 11 Jul 2012 10:15:00 GMT", | ||
} | ||
} | ||
put :update, params: params | ||
expect(Reservation.find(@reservation.id).reservation_time).to eq("Wed, 11 Jul 2012 9:10:00 GMT".to_time) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/reservation_mailer | ||
class ReservationMailerPreview < ActionMailer::Preview | ||
|
||
end |
Oops, something went wrong.