Chapter 3 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What does running ‘bundle update’ accomplish?

A

Updates the gemset to match those specified by the Gemfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the ‘git mv’ command accomplish?

A

Moves the contents of one file to another file. Since we are moving, not copying, the original file is destroyed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we see Heroku’s logs to help diagnose a problem?

A

$ heroku logs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In making a dynamic page, what are actions/views and controllers for?

A

Actions/views contain only static HTML, and controllers contain sets of actions (functions) related by a common purpose.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the syntax for generating a controller?

A

$ rails genreate controller controllerName optionalAction1 optionAction2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we push a branch besides master to BitBucket, thereby changing the branch we are pushing?

A

Include the -u flag and origin parameter, and add one final argument with the name of the branch to push:

$ git push -u origin static-pages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T/F: When giving a generator a controller name, it automatically converts CamelCase to snake_case

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain the following command:

$ rails destroy controller StaticPages home help

A

After generating this controller, we can mimic the command with the ‘destroy’ directive instead to undo changes. Note that additional command line arguments must also be added in order to be included in the rollback

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we undo a database migration we performed with the db:migrate command?

A

$ bundle exec rake db:rollback

OR, to go back to the beginning:

$ bundle exec rake db:migrate VERSION=0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain the rule in the routes.rb file:

get ‘static_pages/home’

A

When we passed the ‘home’ parameter to the generator for the StaticPages controller, Rails added a route to access these pages when given as part of a URL

Furthermore, by using ‘get’ we arrange for the route to respond to a GET request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are four of the most common HTTP operations?

A

GET, POST, PATCH, DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain GET, POST, PATCH, and DELETE in the context of Rails

A

GET: Used to read data; sends a request from client to server to get a page

POST: Used for creating things; a request sent by client to submit a form

PATCH: Updates things on a server

DELETE: Deletes things on a server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Rake?

A

Short for Ruby make; a make-like language written in Ruby

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

T/F: When using scaffolding, the resulting controller uses REST architecture, whereas when only a controller is generated, not all of the REST architecture is used

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When generating a controller, what do the additional parameters do in the controller file?

A

They are added as functions within the controller’s class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Since the initial function in the controller file for a page (i.e. parameter to a controller generator) is empty, how does Rails render the page?

A

Since the controller inherits from ApplicationController, all it needs to do is render the view (i.e. make a static page) and doesn’t need to perform any actions

17
Q

What is the correspondence between actions and views?

A

An action like home has a corresponding view called home.html.erb.

18
Q

Where are views located?

A

In apps/views/controllerName/pageName.html.erb

19
Q

T/F: Rails must contain more than just static HTML.

A

F; Rails can contain just static HTML.

20
Q

What is a test suite?

A

A collection of automated tests for test-driven development.

21
Q

What are some guidelines for developing tests?

A
  • When a test is especially short or simple compared to the application code it tests, lean toward writing the test first.
  • When the desired behavior isn’t yet crystal clear, lean toward writing the application code first, then write a test to codify the result.
  • Because security is a top priority, err on the side of writing tests of the security model first.
  • Whenever a bug is found, write a test to reproduce it and protect against regressions, then write the application code to fix it.
  • Lean against writing tests for code (such as detailed HTML structure) likely to change in the future.
  • Write tests before refactoring code, focusing on testing error-prone code that’s especially likely to break.
22
Q

Where does Rails store generated test scripts?

A

In the tests directory

23
Q

What action does a generated test script use to see if a test has succeeded?

A

An assert statement:

test “should get home” do
get :home
assert_response :success
end

24
Q

How can we run a test suite?

A

$ bundle exec rake test

25
Q

T/F: In test-driven development, a passing test is written first which we get to fail.

A

F; A failing test is written first, and through development we get it to pass.

26
Q

What is the next step after getting a test to pass?

A

Refactoring the code if necessary.

27
Q

In TDD (test-driven development), what is the best place to look when a test fails.

A

Look at the error message, and try to fix what it sees as incorrect.

28
Q

What does “code smell” refer to?

A

When code gets bloated and repetitive during development, and requires refactoring to keep it clean.

29
Q

In tests, what does the ‘assert_select’ method do?

A

It lets us test for the presence of a particular tag; “selector” is a synonym for a tag

30
Q

In ERB, what is the difference between starting a tag with <%= ?

A

Including the = means the return value of the code will be printed to the webpage.

31
Q

In ERB, what does starting a tag with <%= mean?

A

The = means that the return value of the code will be inserted into the template.

32
Q

What is ERB, and what does it let us do

A

Stands for embedded Ruby (template system for dynamic content); allows us to insert Ruby code into HTML.

33
Q

In the default layout file, what does the following code do:

A

It takes the contents of another erb file and replaces the yield statement with that code.

34
Q

What is the default layout template supplied by Rails?

A

app/views/layouts/application.html.erb

35
Q

In the default layout file, what does the following code do:

A

It takes the contents of another erb file and replaces the yield statement with that code.