diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 5f47de225..7db232e3d 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -37,8 +37,9 @@ def log_in(user_or_fixture, password = 'test123') def log_out within :css, '.header' do find(:css, 'i.far.fa-caret-square-down').find(:xpath, '..').click - click_on 'Sign Out' end + + find_link('Sign Out').click end # Pretends the user has clicked the confirmation link in the email they received. diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index e60c01e6c..9cd0a928f 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,6 +1,6 @@ standard_user: email: standard@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: standard_user is_global_admin: false @@ -9,7 +9,7 @@ standard_user: closer: email: closer@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: closer website: https://example.com/closer @@ -22,7 +22,7 @@ closer: editor: email: editor@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: editor is_global_admin: false @@ -33,7 +33,7 @@ editor: deleter: email: delete@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: deleter is_global_admin: false @@ -42,7 +42,7 @@ deleter: moderator: email: moderator@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: moderator is_global_admin: false @@ -51,7 +51,7 @@ moderator: admin: email: admin@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: admin is_global_admin: false @@ -60,7 +60,7 @@ admin: global_moderator: email: global-moderator@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: global-moderator is_global_admin: false @@ -69,7 +69,7 @@ global_moderator: global_admin: email: global-admin@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: global-admin is_global_admin: true @@ -78,7 +78,7 @@ global_admin: no_community_user: email: no_community_user@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: no_community_user is_global_admin: false @@ -88,7 +88,7 @@ no_community_user: system: id: -99 email: system@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: system is_global_admin: true @@ -97,7 +97,7 @@ system: deleted_account: email: deleted@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: deleted_account confirmed_at: 2020-01-01T00:00:00.000000Z @@ -107,7 +107,7 @@ deleted_account: deleted_profile: email: deleted_profile@qpixel-test.net - encrypted_password: abcdefghijklmnopqrstuvwxyz + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' sign_in_count: 1337 username: deleted_profile confirmed_at: 2020-01-01T00:00:00.000000Z diff --git a/test/system/basic_test.rb b/test/system/basic_test.rb deleted file mode 100644 index 3342f0e28..000000000 --- a/test/system/basic_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'application_system_test_case' - -class BasicTest < ApplicationSystemTestCase - test 'newly registered user can sign in after confirming their account' do - email = 'test@test.com' - username = 'Test User' - password = 'test123' - - visit root_url - click_on 'Sign Up' - fill_in 'Email', with: email - fill_in 'Username', with: username - fill_in 'Password', with: password - fill_in 'Password confirmation', with: password - - assert_difference 'User.count' do - click_on 'Sign up' - end - - user = User.last - - confirm_email user - log_in user, password - assert_selector '.notice', text: 'Signed in successfully.' - end -end diff --git a/test/system/login_test.rb b/test/system/login_test.rb new file mode 100644 index 000000000..5f799dbc5 --- /dev/null +++ b/test/system/login_test.rb @@ -0,0 +1,57 @@ +require 'application_system_test_case' + +class LoginTest < ApplicationSystemTestCase + test 'User can register a new account and sign-in to it after confirming their email' do + email = 'test@test.com' + username = 'Test User' + password = 'login_test_1' + + # Sign up for an account + visit root_url + click_on 'Sign Up' + fill_in 'Email', with: email + fill_in 'Username', with: username + fill_in 'Password', with: password + fill_in 'Password confirmation', with: password + + # Check that the user is created in the DB + assert_difference 'User.count' do + click_on 'Sign up' + end + + user = User.last + + # Try logging in directly, this should fail because not confirmed yet + log_in user, password + assert_selector '.notice', text: 'You have to confirm your email address before continuing.' + + # Confirm email and sign in again, should succeed this time + confirm_email user + log_in user, password + assert_selector '.notice', text: 'Signed in successfully.' + end + + test 'User can sign in and is redirected back to the page they were on' do + # Start on the users page + visit users_url + + # Click the sign in button (top right) + # Don't go through log_in helper, since we want to test the sign-in fully here + click_on 'Sign In' + fill_in 'Email', with: users(:standard_user).email + fill_in 'Password', with: 'test123' + click_button 'Sign in' + + # We should see a message that we have signed in, and we should be on the users page again. + assert_selector '.notice', text: 'Signed in successfully.' + assert_current_path users_url + end + + test 'User can sign out' do + log_in :standard_user + assert_selector '.notice', text: 'Signed in successfully.' + + log_out + assert_selector '.notice', text: 'Signed out successfully.' + end +end