From baa914ebca4974443c29d8b4c2c6d6e5495d83f5 Mon Sep 17 00:00:00 2001 From: "Butler, Alexis (UG - Computer Science)" <ab02259@surrey.ac.uk> Date: Wed, 25 Nov 2020 15:49:14 +0000 Subject: [PATCH] User controller / routes test --- test/controllers/users_controller_test.rb | 47 ++++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 40eb2f0..830ab48 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -1,12 +1,47 @@ require 'test_helper' class UsersControllerTest < ActionDispatch::IntegrationTest - test "should get signup page" do - + test 'should get signup page if not logged in' do + get signup_url + assert_response(:success) end - - test "should get close account page" do - + test 'Should not get signup if logged in' do + sign_in_as_tester + get signup_url + assert_redirected_to(root_url) + assert_equal 'Already have an existing account', flash[:warning] + end + test 'should close account if logged in' do + sign_in_as_tester + assert_difference('User.count', -1) do + get shutdown_url + end + assert_redirected_to(root_url) + assert_equal 'Account successfully closed', flash[:warning] + end + test 'should not close account if not logged in' do + assert_no_difference('User.count') do + get shutdown_url + end + assert_redirected_to(root_url) + assert_equal 'Not logged in', flash[:warning] + end + test 'should create a user' do + assert_difference('User.count', +1) do + post signup_url, params: {user: {firstName: 'Alexis', lastName: 'Butler', + email: 'lexieb101@gmail.com', password: '5ecurep@55w0rd', + password_confirmation: '5ecurep@55w0rd'}} + end + assert_redirected_to(root_url) + assert_equal 'Account created', flash[:success] + end + test 'should reject mallformed user creation' do + assert_no_difference('User.count') do + post signup_url, params: {user: {firstName: '', lastName: 'Butler', + email: 'lexieb101@gmail.com', password: '5ecurep@55w0rd', + password_confirmation: '5ecurep@55w0rd', admin: true}} + end + assert_redirected_to(root_url) + assert_equal 'Sorry, something went wrong', flash[:danger] end - end -- GitLab