0
0
Ruby on Railsframework~5 mins

Controller tests in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of controller tests in Rails?
Controller tests check if the controller actions respond correctly to requests, render the right views, and handle data properly.
Click to reveal answer
beginner
Which HTTP methods are commonly tested in Rails controller tests?
GET, POST, PATCH/PUT, and DELETE are the common HTTP methods tested to simulate user actions on resources.
Click to reveal answer
beginner
In Rails controller tests, what does the 'get :index' command do?
It simulates a GET request to the 'index' action of the controller, allowing you to test the response and assigned variables.
Click to reveal answer
intermediate
How do you check if a controller action redirects to another page in Rails tests?
Use 'assert_redirected_to' with the expected path to verify the controller action sends a redirect response.
Click to reveal answer
intermediate
Why is it important to test both successful and unsuccessful controller actions?
Testing both ensures your app handles normal cases and errors gracefully, improving reliability and user experience.
Click to reveal answer
Which method simulates a POST request in Rails controller tests?
Apatch
Bget
Cdelete
Dpost
What does 'assert_response :success' check in a controller test?
AThe action returns a 200 OK status
BThe action redirects to another page
CThe action raises an error
DThe action renders a JSON response
How do you test that a controller action assigns a variable in Rails tests?
Aassert_redirected_to
Bassert_template
Cassigns(:variable_name)
Dassert_equal
Which Rails testing framework is commonly used for controller tests?
AJUnit
BRSpec
CMocha
DJest
What is the purpose of 'assert_template' in controller tests?
AVerify the rendered view template
BCheck the HTTP status code
CTest database changes
DSimulate a user login
Explain how to write a basic controller test for the 'show' action in Rails.
Think about the steps to simulate a request and check the results.
You got /4 concepts.
    Describe why testing both success and failure cases in controller actions is important.
    Consider what happens when things go right and when they go wrong.
    You got /4 concepts.