Skip to content

Instantly share code, notes, and snippets.

@jecrockett
Forked from rwarbelow/week-2-diagnostic.markdown
Last active December 11, 2015 16:53
Show Gist options
  • Save jecrockett/aa1a08eb8b207d686c24 to your computer and use it in GitHub Desktop.
Save jecrockett/aa1a08eb8b207d686c24 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 initially which gets send to the server. The server reads this request (whether it be a get, post, put, delete request), processes the information it needs to process, and then sends back a response to the client. The messages being send back and forth are always just in string form.
  1. Explain when each of these HTTP verbs would be used: GET, POST, PUT, DELETE.
  • GET: This verb would be used when the client is requesting information.
  • POST: This verb would be used when the client is creating or submitting information to the server
  • PUT: This verb would be used when the client is updating or editing information on the server
  • DELETE: This verb would be used when the celint is deleting information from the server.
  1. 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? Necessary Routes:

    • get /index - see records
    • get /index/new - see form to create
    • post /index - submit new record
    • get /index/id - see individual record
    • get /index/id/edit - see form to edit individual record
    • put /index/id - update individual record
    • delete /index/id - delete invidivual record

    We need seven routes because some of the functions need multiple routes. For example, to create a new record or something we need a GET route to render the form to create said record, and a route to POST route to submit that information to the server. We also need to be able to do certain actions in more than one spot. For example, we need to be able to "read" the index, but also each individual record and the forms to edit/change those records.

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

  • Models manage data and logic separate from the user interactiion with a program. It may store/manipulate data based on the requests that the server receives from the client.
  1. Describe the function of views in the MVC structure.
  • Views are the user interface portion of the MVC structure. This is where the HTML is rendered for a user's browser and users would interact with the graphical interface.
  1. Describe the function of controllers in the MVC structure.
  • The controller sends instructions to the views and models based on path of the request 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.
  • A model test is sort of like a unit test. The tests are constrained to interaction within that model and tests for edge cases. These tests ensure that we get the expected result from our various methods. For example, if our model's job is to pull certain information out of a database, we would test that a specific command (i.e. @client.payloads.group(:path)) returns what we expect it to return.
  • A feature test focuses more on the user experience in that it test whether the views interact properly with the models. An example would be using a tool like Capybara to hypothetically navigate the view as if we were a client. We would tell the program to perform a series of actions as if it were using the graphical interface (i.e. in pseudocode...visit turing.io; click on the "Admissions" link; click "start your application now"; assert the current path is apply.turing.io. and that there's a login button on the screen).
  • A controller test checks that browser requests are properly routed to the correct models/views. In this case Capybara is not mimicking the clicks of a user, but rather we're directly sending the string request that a browser/client might submit and checking that our controller recognizes it and properly uses the models and updates the views based on that request.
  1. What does ActiveRecord do? Why do we use ORMs like ActiveRecord?
  • ORMs allow us to create relationships between different sets of information and specify how they relate to one another. This let's us organize data and manipulate it easier. Since ORMs like ActiveRecord are specialized for handling this type of information, it's also a lot easier and faster to access/manipulate the data this way rather in memory using a language like Ruby.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment