-
Notifications
You must be signed in to change notification settings - Fork 26
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
Ports - Margaret & Steph #1
base: master
Are you sure you want to change the base?
Conversation
…w and index for driver, created show and index html.erb
…tml.erb files and have new driver form
… on the show page
…n user that all trips will also be deleted
… routes in driver and passenger
…edit and delete trips
Rideshare RailsWhat We're Looking For
|
trip: { | ||
date: "April 19, 2019", | ||
cost: 1445, | ||
passenger_id: Passenger.last.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things:
- This isn't in an
it
block so you don't have a Passenger or Driver at this stage. - Unless you have a fixture or a
before
block that creates a passenger this test will have an error! :(
@@ -0,0 +1,15 @@ | |||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice try at fixtures, as you learned this week you can't set the foreign key fields like driver_id in this way. Instead do something like:
driver: one
passenger: two
end | ||
|
||
describe "create" do | ||
it "should create a new trip" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There really isn't a form being submitted for the trips controller, Instead the trip data is being set automatically
must_respond_with :redirect | ||
end | ||
|
||
it "returns an error for and invalid trip" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you don't have a form submitting to the create action, instead a link is used. The only thing you need to test is when the create action is given an invalid passenger id.
trip: { | ||
date: date, | ||
cost: cost, | ||
passenger_id: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least you are checking with an invalid passenger id.
@@ -0,0 +1 @@ | |||
<%= link_to "All Drivers", drivers_path %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this page really used? Should it be?
Also you have a trips/new.html.erb view, do you need one?
@@ -0,0 +1,4 @@ | |||
class Trip < ApplicationRecord | |||
belongs_to :driver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also add validations to prevent a trip with an invalid cost or rating.
validates :phone_number, presence: true | ||
|
||
def total_charges | ||
return (self.trips.sum { |trip| trip.cost }) / 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to show this with decimal numbers you should divide by 100.0 or convert it to a float before the division.
|
||
validates :name, presence: true | ||
validates :phone_number, presence: true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another nice business logic method would be to make a request_trip
method which would generate a trip for a specific instance of passenger. That would help you DRY up your controller.
end | ||
|
||
def create | ||
passenger = Passenger.find_by(id: params[:trip][:passenger_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passenger_id is a route parameter, not a field submitted by a form. Instead this should be:
passenger = Passenger.find_by(id: params[:passenger_id])
Rideshare-Rails
Congratulations! You're submitting your assignment! These comprehension questions should be answered by both partners together, not by a single teammate.
Comprehension Questions