Skip to content

Instantly share code, notes, and snippets.

@bethsecor
Forked from rwarbelow/week-2-diagnostic.markdown
Last active December 11, 2015 16:47
Show Gist options
  • Save bethsecor/70ae84ce5d28b513407a to your computer and use it in GitHub Desktop.
Save bethsecor/70ae84ce5d28b513407a 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 (generally a browser) will make a request for something from a server, most commonly to render a page or post some data. The server will respond with a status code, a header, and sometimes a body. The client receives that response and if the status is ok (200) can render the page requested. 2. Explain when each of these HTTP verbs would be used: GET, POST, PUT, DELETE.

GET is used for getting information for the client to render, GET requests must be idempotent. POST requests send data to the server from the client, PUT will update data from the server, DELETE will tell the server to delete data. 3. 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?

CRUD stands for create, read, update, and delete. To create you need both GET and POST. To read you need GET. To update you need GET and PUT. To delete you need GET and DELETE. You need seven routes because you need several GET requests to display a view/data to the client so they can create, update, or delete data. 4. Describe the function of models in the MVC structure.

The models are in charge of talking to the database and manipulating it so that it can send the final data in the format needed to the controller. 5. Describe the function of views in the MVC structure.

The views are what are rendered and displayed by a browser (the client). They are mostly HTML, but when using sinatra, ruby code can be embedded to display data sent from the controller. 6. Describe the function of controllers in the MVC structure.

The controllers manage the requests coming in from the client, and talk to the models to get data needed from the database. 7. 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.

An example model test would be a test for creating data in the database, or getting data from the database and getting the expected result from a calculation. An example feature test would use capybara to test whether content on a page is in fact there and shows up correctly. An example controller test would be to test that the correct response status code or the correct info in the body was sent back to the client. 8. What does ActiveRecord do? Why do we use ORMs like ActiveRecord?

ActiveRecord allows us to create tables, update tables by adding, removing, renaming columns, etc., in a SQL database that has already been created.

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