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.
A couple of things:
- This isn't in an
itblock so you don't have a Passenger or Driver at this stage. - Unless you have a fixture or a
beforeblock 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.
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.
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.
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.
At least you are checking with an invalid passenger id.
| @@ -0,0 +1 @@ | |||
| <%= link_to "All Drivers", drivers_path %> No newline at end of file | |||
There was a problem hiding this comment.
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.
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.
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.
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.
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