Conversation
Movie controller methods and tests.
Video StoreWhat We're Looking For
|
| def show | ||
| customer = Customer.find_by(id: params[:id]) | ||
| if customer | ||
| render status: :ok, json: customer.as_json(only: [:id, :name, :registered_at, :adress, :city, :state, :postal_code, :phone, :movies_checked_out_count]), status: :ok |
There was a problem hiding this comment.
Small style note: not all text editors wrap lines for you. This line is so long that on GitHub I have to scroll horizontally to see all the pieces. You can make this easier to read by putting a newline after any given comma in a statement.
| if customer | ||
| render status: :ok, json: customer.as_json(only: [:id, :name, :registered_at, :adress, :city, :state, :postal_code, :phone, :movies_checked_out_count]), status: :ok | ||
| else | ||
| render status: :not_found, json: { ok: false, messages: "Movie was not found!" } |
There was a problem hiding this comment.
This is a customer... Copy pasta is dangerous!
| def check_out | ||
| rental = Rental.new(rental_params) | ||
| customer = Customer.find_by(id: rental.customer_id) | ||
| movie = Movie.find_by(id: rental.movie_id) |
There was a problem hiding this comment.
You have a bunch of business logic here! Would it be possible to encapsulate this in a model method? Something like
rental.check_out(customer_id, movie_id)
might be a good interface. That would make this logic easier to test as well.
|
|
||
| it "returns json" do | ||
| get customers_path | ||
| expect(response.header["Content-Type"]).must_include "json" |
There was a problem hiding this comment.
This isn't checking the actual JSON to see if the contents are correct.
| get movies_index_url | ||
| value(response).must_be :successful? | ||
| end | ||
|
|
| due_date: Date.today + 7, | ||
| } | ||
| } | ||
| describe "checkout" do |
There was a problem hiding this comment.
These tests don't cover cases I would expect to see. What if there is bad data? What data is being sent back?
Also, I don't see any tests written for the checkin route.
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions
POST /rentals/check-inendpoint? What does the time complexity depend on? Explain your reasoning.