Skip to content

Commit

Permalink
Update tests and factories
Browse files Browse the repository at this point in the history
  • Loading branch information
rlmoser99 committed Feb 22, 2021
1 parent 056e48a commit 6e8beb1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 39 deletions.
10 changes: 5 additions & 5 deletions spec/factories/airports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
code { "TOP" }
location { "Springfield, US" }

trait :east_coast do
trait :new_york_city do
code { "NYC" }
end

trait :north_california do
trait :san_francisco do
code { "SFO" }
end

trait :south_california do
trait :los_angeles do
code { "LAX" }
end

trait :atlanta_layover do
trait :atlanta do
code { "ATL" }
end

trait :chicago_layover do
trait :chicago do
code { "ORD" }
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/passenger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
it { is_expected.to belong_to(:booking) }
it { is_expected.to have_many(:flights).through(:booking) }
end

describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:email) }
end
end
9 changes: 7 additions & 2 deletions spec/requests/bookings_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

require 'rails_helper'

# RSpec.describe "Bookings", type: :request do
RSpec.describe "Bookings", type: :request do
it "handles a missing booking correctly" do
get booking_path("not-here")

# end
expect(response).to redirect_to(root_url)
expect(flash[:alert]).to eq("Sorry, this booking does not exist.")
end
end
7 changes: 0 additions & 7 deletions spec/requests/passengers_request_spec.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/requests/tickets_request_spec.rb

This file was deleted.

10 changes: 5 additions & 5 deletions spec/services/booking_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require "rails_helper"

RSpec.describe BookingOptions do
let(:san_fran) { create(:airport, :north_california) }
let(:new_york) { create(:airport, :east_coast) }
let(:atlanta) { create(:airport, :atlanta_layover) }
let(:chicago) { create(:airport, :chicago_layover) }
let(:san_fran) { create(:airport, :san_francisco) }
let(:new_york) { create(:airport, :new_york_city) }
let(:atlanta) { create(:airport, :atlanta) }
let(:chicago) { create(:airport, :chicago) }

# 2 direct flights SFO to NYC
let(:morning_SFO_NYC) { create(:tomorrow_morning_flight, origin_airport: san_fran, destination_airport: new_york) }
Expand Down Expand Up @@ -91,7 +91,7 @@
end

context 'when origin and destination are too close for layover' do
let(:los_angeles) { create(:airport, :south_california) }
let(:los_angeles) { create(:airport, :los_angeles) }

# 2 direct flights SFO to LAX
let(:morning_SFO_LAX) { create(:tomorrow_morning_flight, origin_airport: san_fran, destination_airport: los_angeles) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@

require "rails_helper"

RSpec.describe "view available flights", type: :system do
let(:tomorrow) { Time.zone.tomorrow }
let!(:chicago) { create(:airport, location: "Chicago, IL", code: "ORD") }
let!(:new_york) { create(:airport, location: "New York City, NY", code: "NYC") }
let!(:atlanta) { create(:airport, location: "Atlanta, GA", code: "ATL") }
let!(:chicago_to_newyork) do
create(:flight, id: 1, origin_airport: chicago, destination_airport: new_york, departure_date: tomorrow)
end
let!(:chicago_to_atlanta) do
create(:flight, id: 2, origin_airport: chicago, destination_airport: atlanta, departure_date: tomorrow)
end
RSpec.describe "add booking", type: :system do
let!(:chicago) { create(:airport, :chicago, location: "Chicago, IL") }
let!(:new_york) { create(:airport, :new_york_city, location: "New York City, NY") }
let!(:atlanta) { create(:airport, :atlanta) }

let!(:ORD_NYC) { create(:tomorrow_morning_flight, id: 1, origin_airport: chicago, destination_airport: new_york) }
let!(:ORD_ATL) { create(:tomorrow_morning_flight, id: 2, origin_airport: chicago, destination_airport: atlanta) }

it "allows a user to select flight options and create a booking" do
it "allows a user to search flights, select a booking option, and create a booking" do
visit "/"
select("Chicago, IL", from: "origin_id")
select("New York City, NY", from: "destination_id")
select(2, from: "passenger_count")
fill_in("departure_date", with: tomorrow)
fill_in("departure_date", with: Time.zone.tomorrow)
click_on("Find Flights")
within(".flight-results") do
expect(page).to have_content("Available Flights")
Expand Down

0 comments on commit 6e8beb1

Please sign in to comment.