Conversation
Rideshare RailsWhat We're Looking For
|
| must_redirect_to trip_path(valid_id) | ||
| end | ||
|
|
||
| it "must respond with a 404 if the trip was not found" do |
There was a problem hiding this comment.
What about if you try to update a trip with invalid data (like a negative cost or something).
| expect(flash[:success]).must_equal "Connected to Driver: #{avail_driver.name} for requested trip" | ||
| end | ||
|
|
||
| it "will redirct and return error message flash if no available drivers" do |
There was a problem hiding this comment.
This is a great test, although "redirct" should be "redirect"
| @driver = Driver.find(@trip.driver_id) | ||
| @driver.update(available: false) | ||
| end | ||
| it "will update trip rating" do |
There was a problem hiding this comment.
You should also have a test with an invalid trip id.
| expect(@trip.rating).must_equal 4 | ||
| end | ||
|
|
||
| it "will update status of driver to available from unavailable" do |
There was a problem hiding this comment.
Wait... a driver should be available after this action, not before... small grammar issue.
| def create | ||
| passenger_id = params[:passenger_id] | ||
| @passenger = Passenger.find_by(id: passenger_id) | ||
| driver = Driver.next_available |
There was a problem hiding this comment.
Good business logic method.
However look at the length of this create method. You should abstract some of the logic out into the model.
| @@ -0,0 +1,4 @@ | |||
| <section class="form trip"> | |||
| <h1>Edit Trip</h1> | |||
| <%= render partial: "trips_form", locals: {action: "Update"} %> | |||
There was a problem hiding this comment.
You don't need a partial here as you don't have a new trip form.
| <%= f.select :passenger_id, Passenger.all.map{ |passenger| [passenger.name, passenger.id] } %> | ||
|
|
||
| <%= f.label :cost%> | ||
| <%= f.number_field :cost, :required => true, in: 1.65..100.00, step: 0.01 %> |
There was a problem hiding this comment.
Nice work with all the front-end validations
| validates :car_make, presence: true | ||
| validates :car_model, presence: true | ||
|
|
||
| def self.next_available |
|
|
||
| validates :name, presence: true | ||
| validates :phone_num, presence: true | ||
|
|
There was a problem hiding this comment.
You should also consider requesting a trip as a method in the Passenger class.
| patch "/trips/:id/complete", to: "trips#complete", as: "complete_trip" | ||
|
|
||
| resources :passengers do | ||
| resources :trips, only: [:create] |
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