0
0
Ruby on Railsframework~10 mins

Integration tests in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an integration test class inheriting from the correct base class.

Ruby on Rails
class UsersLoginTest < [1]
  # test code here
end
Drag options to blanks, or click blank then click option'
AActionDispatch::IntegrationTest
BActiveSupport::TestCase
CApplicationRecord
DActionController::Base
Attempts:
3 left
💡 Hint
Common Mistakes
Using ActiveSupport::TestCase instead of ActionDispatch::IntegrationTest
Confusing controller tests with integration tests
2fill in blank
medium

Complete the code to simulate a GET request to the login path in an integration test.

Ruby on Rails
get [1]
Drag options to blanks, or click blank then click option'
Ausers_path
Blogin_path
Csignup_path
Droot_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using users_path which is for user index
Using root_path which is the home page
3fill in blank
hard

Fix the error in the assertion to check if the login form is present in the response body.

Ruby on Rails
assert_select "form[action=?]", [1]
Drag options to blanks, or click blank then click option'
Asignup_path
Blogout_path
Clogin_path
Dusers_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using logout_path which is for logging out
Using signup_path which is for new user registration
4fill in blank
hard

Fill both blanks to simulate a POST login request with email and password parameters.

Ruby on Rails
post login_path, params: { session: { email: [1], password: [2] } }
Drag options to blanks, or click blank then click option'
A"user@example.com"
B"password"
C"wrongpass"
D"admin@example.com"
Attempts:
3 left
💡 Hint
Common Mistakes
Using symbols instead of strings for email and password
Mixing up email and password values
5fill in blank
hard

Fill both blanks to check that after login, the user is redirected to the profile page and the flash message is not empty.

Ruby on Rails
assert_redirected_to [1]
follow_redirect!
assert_template [2]
assert_not flash.empty?
Drag options to blanks, or click blank then click option'
Auser_path(@user)
B:users/show
C:users/profile
Droot_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using root_path instead of user_path(@user)
Using :users/profile which is not a standard template name