Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addie's Ride Share #25

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
67480f3
set up Rakefile and spec_helper
add2point71dots Mar 6, 2017
fc42834
set up initial file structure
add2point71dots Mar 6, 2017
5c4a935
sets up and tests initialize
add2point71dots Mar 6, 2017
ef9dfcc
Sets up and tests initialize for Rider
add2point71dots Mar 7, 2017
1296d00
Added .gitignore
add2point71dots Mar 7, 2017
3a81cc6
adds and tests initialize for Trip
add2point71dots Mar 7, 2017
8206e33
tinkering with require stuff
add2point71dots Mar 7, 2017
1a4ecf9
changed my befores to lets in tests and took out some comments in cla…
add2point71dots Mar 7, 2017
1b33663
raise argument errors for invalid information in initialize (and test…
add2point71dots Mar 7, 2017
fc16386
put everything in a RideShare module
add2point71dots Mar 7, 2017
2103dad
Adds and tests Driver.all method
add2point71dots Mar 7, 2017
1c1304d
Adds and tests Rider.all
add2point71dots Mar 7, 2017
ab077a6
Validates info when creating a new Rider (and tests that)
add2point71dots Mar 7, 2017
f050ae8
Put validation methods in RideShare module and cleaned up some code
add2point71dots Mar 7, 2017
70eaa87
Worked on Trip.all method and allowed IDs to be 0
add2point71dots Mar 8, 2017
739f891
Adds and tests Driver.find
add2point71dots Mar 8, 2017
bb68fdd
Adds and tests Rider.find method
add2point71dots Mar 8, 2017
5836a3d
working on the Trip.find_driver_trips
add2point71dots Mar 8, 2017
b7f3aa1
working on Trip.find_rider_trips method
add2point71dots Mar 8, 2017
4367649
Moved validation methods to separate module, plus some refactoring
add2point71dots Mar 8, 2017
cc7c8a9
made validation methods private
add2point71dots Mar 8, 2017
bfe2a6f
Adds and tests Driver.trips and messed with how classes are put in th…
add2point71dots Mar 8, 2017
b0df183
Adds and tests Driver.avg_rating
add2point71dots Mar 8, 2017
7742614
Adds and tests Rider.trips method
add2point71dots Mar 8, 2017
76184fb
require pry
add2point71dots Mar 8, 2017
d10b6d6
ignore a file I was playing around with
add2point71dots Mar 8, 2017
e2a21dd
Adds and tests Rider.drivers method
add2point71dots Mar 9, 2017
38a7b20
Added a comment for smthg to work on later
add2point71dots Mar 9, 2017
90e49a6
Adds and tests Trip.driver method
add2point71dots Mar 9, 2017
bc80463
Adds and tests Trip#rider method
add2point71dots Mar 9, 2017
475411c
put in some reminder comments
add2point71dots Mar 11, 2017
be92b35
Forces VINs to be 17 characters
add2point71dots Mar 11, 2017
817091b
changed validation of trip rating
add2point71dots Mar 12, 2017
a57f2bc
Added test for date input
add2point71dots Mar 13, 2017
11b6bfe
Minor formatting changes in test files
add2point71dots Mar 13, 2017
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
Prev Previous commit
Next Next commit
Forces VINs to be 17 characters
add2point71dots committed Mar 11, 2017
commit be92b358b3c77e2920bf586a0a4473ea4b5233c0
2 changes: 1 addition & 1 deletion lib/driver.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Driver
def initialize(driver_hash)
@id = validate_int(driver_hash[:id], "Driver ID")
@name = validate_string(driver_hash[:name], "Name")
@vin = validate_string(driver_hash[:vin], "VIN")
@vin = validate_string_length(driver_hash[:vin], "VIN", 17)
end

def self.all
8 changes: 6 additions & 2 deletions lib/validation.rb
Original file line number Diff line number Diff line change
@@ -5,15 +5,19 @@ def validate_int(field, field_name)
if field.class != Integer || field < 0
raise ArgumentError.new("Required field #{field_name} must be a non-negative integer.")
end

return field
end

def validate_string(field, field_name)
if field.class != String || field == ""
raise ArgumentError.new("Required field #{field_name} must be a non-empty string.")
end

return field
end

def validate_string_length(field, field_name, length)
valid_string = validate_string(field, field_name)
raise ArgumentError.new("#{field_name} is invalid length") if valid_string.length != length
return valid_string
end
end
12 changes: 9 additions & 3 deletions specs/driver_spec.rb
Original file line number Diff line number Diff line change
@@ -27,16 +27,22 @@
proc { RideShare::Driver.new(driver_hash2) }.must_raise ArgumentError
end

it "Only accepts non-empty strings for name and VIN" do
it "Only accepts non-empty strings for name" do
driver_hash1 = { id: 4, name: "", vin: "1XKAD49X2DJ395724" }
driver_hash2 = { id: 4, name: 45, vin: "1XKAD49X2DJ395724" }

proc { RideShare::Driver.new(driver_hash1) }.must_raise ArgumentError
proc { RideShare::Driver.new(driver_hash2) }.must_raise ArgumentError
end

driver_hash3 = { id: 4, name: "Ada", vin: "" }
driver_hash4 = { id: 4, name: "Ada", vin: [] }
it "Only accepts VINs that are strings of length 17" do
driver_hash1 = { id: 4, name: "Ada", vin: [] }
driver_hash2 = { id: 4, name: "Ada", vin: "" }
driver_hash3 = { id: 4, name: "Ada", vin: "1XKAD49X2DJ39572" }
driver_hash4 = { id: 4, name: "Ada", vin: "1XKAD49X2DJ3957246" }

proc { RideShare::Driver.new(driver_hash1) }.must_raise ArgumentError
proc { RideShare::Driver.new(driver_hash2) }.must_raise ArgumentError
proc { RideShare::Driver.new(driver_hash3) }.must_raise ArgumentError
proc { RideShare::Driver.new(driver_hash4) }.must_raise ArgumentError
end