-
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.
-
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.
-
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.
- 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.
- 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.
- 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.
- 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)
- 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.