Complete the code to write a simple test method in Rails using Minitest.
def test_[1]_is_valid assert true end
The test method name should describe what is being tested. Here, model_validation is a common test name in Rails.
Complete the code to assert that a Rails model is invalid without a required attribute.
user = User.new(name: nil)
assert_equal [1], user.valid?The test checks that the user is not valid when the name is missing, so we use assert_equal false, user.valid?.
Fix the error in the test that checks the response status of a controller action.
get :index
assert_response [1]The index action should respond with HTTP status 200 (OK) if successful.
Fill both blanks to create a test that checks a model's attribute presence validation.
test "[1] presence" do user = User.new([2]: nil) assert_not user.valid? end
This test checks that the name attribute must be present for the user to be valid.
Fill all three blanks to write a test that checks a controller redirects after creating a record.
post :create, params: { user: { [1]: "test", [2]: "test@example.com" } }
assert_redirected_to [3]_pathThe test posts user data with name and email, then asserts the redirect goes to the user_path.