Skip to content

Instantly share code, notes, and snippets.

@afg419
Forked from rwarbelow/week-2-diagnostic.markdown
Last active December 11, 2015 16:46
Show Gist options
  • Save afg419/8bde90e216e5e8e8dd19 to your computer and use it in GitHub Desktop.
Save afg419/8bde90e216e5e8e8dd19 to your computer and use it in GitHub Desktop.
Week 2 Diagnostic
  1. Describe the request-response cycle. Start with the client making a request.

The client makes a request, which consists in the path, verb, params, and other elements of the body. The request is sent, via a complicated chain of name lookup servers, to the intended server. At this point the request is past through the rack (if it is a rack app) until it finally hits the web app intended. The web app then may do any of a variety of things, usually some kind of CRUD functionality on a database. Then, depending on the elements of the request, the web app emits a response which looks rather similar to the request -- headers and body -- back to the client. This usually contains some html to be rendered on the clients computer.

  1. Explain when each of these HTTP verbs would be used: GET, POST, PUT, DELETE. GET: viewing database information. POST: adding new information to a database. PUT: updating database information. DELETE: removing database information.

  2. What are all of the necessary routes for full CRUD functionality in Sinatra app? Why do we need seven routes when there are only four CRUD actions?

  • A GET route to render index.
  • A GET route to render specific data
  • A GET route to render a form for adding new data.
  • A POST route to actually add the new data.
  • A GET route to render a form for updating data.
  • A POST/PUT route to actually update the data.
  • A GET route to render data to be deleted.
  • A POST/Delete route to delete the data.
  • ... And error route for errors?

Seven routes for four functions, because users need to see in order to click or type.

  1. Describe the function of models in the MVC structure.

Models are to interact directly with the database, drawing information out, wrapping them in ruby objects, and sending them back to the controller to be rendered in views.

  1. Describe the function of views in the MVC structure.

Views are the direct interaction with the client. They render visible text, images, input boxes, and buttons on a clients computer.

  1. Describe the function of controllers in the MVC structure.

Controllers receive requests from the client, and execute various instructions (usually first involving a model) depending on the path and verb received.

  1. What is the difference between model tests, feature tests, and controller tests? Give an example of functionality tested using a model test, functionality tested in a feature test, and functionality tested in a controller test.

Model tests test the functionality of the model's interactions with the database. They verify that data is loaded and extracted correctly. Example: That params from a request get parsed and inserted into database table(s) correctly.

Feature tests test the user story functionality... whether the webapp renders as it is intended, including the data rendered from CRUD manipulations of the database. Example: testing that the homepage renders with the appropriate links.

Controller tests test the non-browser interactions with the website directly. They verify that requests are redirected by the controller correctly when gems like Capybara are incapable of doing so as no views are actually returned in a response. Example: testing that curl requests are returned the correct status codes.

  1. What does ActiveRecord do? Why do we use ORMs like ActiveRecord?

ActiveRecord gives a translator between the ruby language and SQL, the language used to query many databases like PostrgeSQL. We use them because... you know, who wants to learn SQL? Also they contain many ruby wrappers of custom SQL methods allowing for very fast and powerful database queries which otherwise would be difficult in raw SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment