Stateless Code | Write System Tests for Devise Login and Logout @StatelessCode | Uploaded November 2022 | Updated October 2024, 1 hour ago.
Having tested user sign up in the previous video we move on to testing the user login and logout experiences.
We have actually already tested this in our happy path of the sign up test, so we can extract that code into our ApplicationSystemTestCase class, which is the superclass of all our browser system tests in order to reuse it in our other tests. We will also use user login on nearly every future browser test, so it makes sense to distill that functionality into methods (login_with_user!) and (login_with_credentials!) we can call from the setup blocks of our other tests.
We run into some difficulty because the user's password isn't available to us in our test context. We solve for this by creating a constant Hash that has the fixture user emails as the keys and their passwords as the values. When the login_with_user! method is called, we call login_with_credentials! under the hood and get that password from the Hash. If we ever add any new User records to the fixture in the future, we need to remember to also add them to the FIXTURE_USER_PASSWORDS Hash in our test_helper.
Once this hurdle is cleared, the rest of the test implementations for our negative tests and the logout test are fairly straightforward.
This video covers:
00:00:12 Introduction
00:02:17 Demonstrate login and logout functionality (both positive and negative)
00:03:51 Create test class
00:07:19 Create shells for test methods to be implemented
00:08:51 Extract login code and assertions from sign up test into ApplicationSystemTestCase to reuse
00:17:15 Try to implement login test and debug login_with_user! method, use email and password instead
00:28:22 Create a constant hash to get fixture user passwords and get login to where I want it
00:37:30 Implement negative login tests
00:40:41 Implement logout test
00:45:02 Fix RuboCop offenses, commit, push, update project
#ruby #rails7 #rails #rubyonrails #rubygems #codecast #screencast #github #opensource #minitest #TDD #agile #NerdDice #DnD #roleplaying #softwaredevelopment #learntocode #tailwind #postgresql #rubocop #devise #turbo #controllers #views #selenium #capybara #systemtest
See other related StatelessCode videos:
- Write Browser Tests for Devise Sign Up youtu.be/hd62zAGfTQk
This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.
Having tested user sign up in the previous video we move on to testing the user login and logout experiences.
We have actually already tested this in our happy path of the sign up test, so we can extract that code into our ApplicationSystemTestCase class, which is the superclass of all our browser system tests in order to reuse it in our other tests. We will also use user login on nearly every future browser test, so it makes sense to distill that functionality into methods (login_with_user!) and (login_with_credentials!) we can call from the setup blocks of our other tests.
We run into some difficulty because the user's password isn't available to us in our test context. We solve for this by creating a constant Hash that has the fixture user emails as the keys and their passwords as the values. When the login_with_user! method is called, we call login_with_credentials! under the hood and get that password from the Hash. If we ever add any new User records to the fixture in the future, we need to remember to also add them to the FIXTURE_USER_PASSWORDS Hash in our test_helper.
Once this hurdle is cleared, the rest of the test implementations for our negative tests and the logout test are fairly straightforward.
This video covers:
00:00:12 Introduction
00:02:17 Demonstrate login and logout functionality (both positive and negative)
00:03:51 Create test class
00:07:19 Create shells for test methods to be implemented
00:08:51 Extract login code and assertions from sign up test into ApplicationSystemTestCase to reuse
00:17:15 Try to implement login test and debug login_with_user! method, use email and password instead
00:28:22 Create a constant hash to get fixture user passwords and get login to where I want it
00:37:30 Implement negative login tests
00:40:41 Implement logout test
00:45:02 Fix RuboCop offenses, commit, push, update project
#ruby #rails7 #rails #rubyonrails #rubygems #codecast #screencast #github #opensource #minitest #TDD #agile #NerdDice #DnD #roleplaying #softwaredevelopment #learntocode #tailwind #postgresql #rubocop #devise #turbo #controllers #views #selenium #capybara #systemtest
See other related StatelessCode videos:
- Write Browser Tests for Devise Sign Up youtu.be/hd62zAGfTQk
This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.