Skip to content

Instantly share code, notes, and snippets.

@Jlawlzz
Forked from rwarbelow/week-2-diagnostic.markdown
Last active December 11, 2015 16:52
Show Gist options
  • Save Jlawlzz/cc09127e65aef25b3c76 to your computer and use it in GitHub Desktop.
Save Jlawlzz/cc09127e65aef25b3c76 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. CLIENT-RESPONSE - a client sends a GET '/sources' request to the server CONTROLLER-RECIEVE = a the controller recieves the '/sources' request and routes to Model MODEL-LOGIC = the model pulls any applicable data from database into objects to be used. Any logic is now applied. VIEW = the controller passes indicated logic data to a view to be inserted into a HTML/CSS format CONTROLLER-SEND = the controller sends the view back to the client in a valid response.

  2. Explain when each of these HTTP verbs would be used: GET, POST, PUT, DELETE. GET - a client sends a get request when they want to access data/views from the server. POST - a client sends a post request when they are sending data to be processed/entered into the server database. PUT - a client sends a put request when they are sending data to update info on the server database. DELETE - a client sends a delete request when they are requested for a set of data on the server database to be deleted.

  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?

GET '/' POST database GET database PUT database (actually a GET and modified POST) DELETE database (actually a GET and modified POST) Error

We need 7 routes because PUT and DELETE need to utilize two methods rather than one.

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

Models represent the logic/database relation component of MVC. This is where any relevant database info is pulled into the app as an object, and operated on.

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

Views represent the html/css pages that will be delivered to the client. This is where any (front-end) design choices outside of vanilla html are implemented.

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

Controllers represent the routing function that receives/delivers requests from the client to server, and back to the client.

  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 Test: Model tests isolate and validate a single function or method in ruby. (example: test_does_validator_parse_json) Feature Test: A Feature test validates a process or feature of your program . These tests are one level higher up than a model test. (example: test_user_can_create_account, test_user_can_checkout_after_adding_to_cart) Controller Test: A Controller test validates functionality from the server-client level, to test at this level, a tool like capybara should be used. (example: test_user_sees_relavent_data_after_posting_for_specific_data)

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

Active record asks as a translator between ruby and our database (sql, postgress). We use ORM's like ActiveRecord because they allow us to interact with databases (from our language of choice) with a more natural and streamlined syntax and logic.

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