Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created model layer - added specs for FlightSelector and ReservationS…
…ystem
- Loading branch information
Showing
12 changed files
with
93 additions
and
49 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
class Flight | |||
attr_accessor :flight_number, :itineraries | |||
|
|||
def initialize(flight_number) | |||
@flight_number = flight_number | |||
@itineraries = [] | |||
end | |||
|
|||
def add_itinerary(itinerary) | |||
@itineraries << itinerary | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
class FlightSelector | |||
attr_accessor :flight_list | |||
|
|||
def initialize(flight_list) | |||
@flight_list = flight_list | |||
end | |||
|
|||
def search(itinerary) | |||
@flight_list.select { |flight| flight.itineraries.include?(itinerary) } | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
class Itinerary | |||
attr_accessor :from, :to, :date | |||
def initialize(from, to, date) | |||
@from = from | |||
@to = to | |||
@date = date | |||
end | |||
|
|||
def ==(another_object) | |||
self.from == another_object.from && self.to == another_object.to && self.date == another_object.date | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
class ReservationSystem | |||
def self.book_ticket(flight, itinerary, passenger) | |||
OpenStruct.new(flight_number: flight.flight_number, | |||
from: itinerary.from, | |||
to: itinerary.to, | |||
date: itinerary.date, | |||
passenger_name: passenger.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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
# $LOAD_PATH << File.expand_path('../../../app/models', __FILE__) | |||
Dir[File.dirname(__FILE__) + "/../../app/models/*.rb"].each do |file| | |||
require file | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require_relative '../../app/models/flight_selector' | |||
|
|||
describe FlightSelector do | |||
let (:itinerary1) { stub(:itinerary1) } | |||
let (:itinerary2) { stub(:itinerary2) } | |||
let (:flight1) { stub(:flight1, itineraries: [itinerary1]) } | |||
let (:flight2) { stub(:flight2, itineraries: [itinerary2]) } | |||
|
|||
before do | |||
@it = FlightSelector.new([flight1, flight1]) | |||
end | |||
|
|||
it "should search for flights based on itinerary" do | |||
@it.search(itinerary1).should include(flight1) | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
require_relative '../../app/models/flight' | |||
|
|||
describe Flight do | |||
|
|||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
require_relative '../../app/models/itinerary' | |||
|
|||
describe Itinerary do | |||
|
|||
context "compare itineraries" do | |||
it "should be same if from/to/date are same" do | |||
it1 = Itinerary.new("Hyderabad", "Bangalore", "01/01/2012") | |||
it2 = Itinerary.new("Hyderabad", "Bangalore", "01/01/2012") | |||
it1.should eq(it2) | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
require_relative '../../app/models/reservation_system' | |||
|
|||
describe ReservationSystem do | |||
|
|||
|
|||
|
|||
end |