<commit_before>require 'test_helper'

class UsersControllerTest < ActionController::TestCase

  setup :build_basic_user_dict

  # Getting basic pages

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:users)
  end

  test "should get show" do
    become_user
    get(:show, {"id" => users(:user).id})
    assert_response :success
    assert_not_nil assigns(:user)
    assert_equal users(:user).id, assigns(:user).id
  end

  test "should get new" do
    get :new
    assert_response :success
    assert_not_nil assigns(:user)
  end

  # Creating user tests

  test "should create user" do
    assert_difference("User.count") do
      post :create, user: @basic_user
    end
    assert_redirected_to log_in_path
    assert_equal "Signed up!", flash[:notice]
  end

  test "should log user in at creation time" do
    assert_difference("User.count") do
      post :create, user: @basic_user
    end
    assert_not_nil session[:user_id], "KNOWN BUG: See Isses#10"
  end

  test "password and confirm must match" do
    assert_difference("User.count", 0) do
      @basic_user[:password_confirmation] = "<PASSWORD>"
      post :create, user: @basic_user
    end
    assert_equal "Password confirmation doesn't match Password", get_message
    assert_nil session[:user_id]
  end

  test "email must be unique" do
    assert_difference("User.count", 0) do
      @basic_user[:email] = users(:dfarrell07).email
      post :create, user: @basic_user
    end
    assert_equal "Email has already been taken", get_message
  end

  # Creating admin tests

  test "should not create admin when logged out" do
    assert_difference("User.count", 0) do<commit_msg>Better response to user creation, fixes #10.<commit_after>require 'test_helper'

class UsersControllerTest < ActionController::TestCase

  setup :build_basic_user_dict

  # Getting basic pages

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:users)
  end

  test "should get show" do
    become_user
    get(:show, {"id" => users(:user).id})
    assert_response :success
    assert_not_nil assigns(:user)
    assert_equal users(:user).id, assigns(:user).id
  end

  test "should get new" do
    get :new
    assert_response :success
    assert_not_nil assigns(:user)
  end

  # Creating user tests

  test "should create user" do
    assert_difference("User.count") do
      post :create, user: @basic_user
    end
    assert_equal "Signed up!", flash[:notice]
  end

  test "should send to log in page at creation time" do
    assert_difference("User.count") do
      post :create, user: @basic_user
    end
    assert_redirected_to log_in_path
  end

  test "password and confirm must match" do
    assert_difference("User.count", 0) do
      @basic_user[:password_confirmation] = "<PASSWORD>"
      post :create, user: @basic_user
    end
    assert_equal "Password confirmation doesn't match Password", get_message
    assert_nil session[:user_id]
  end

  test "email must be unique" do
    assert_difference("User.count", 0) do
      @basic_user[:email] = users(:dfarrell07).email
      post :create, user: @basic_user
    end
    assert_equal "Email has already been taken", get_message
  end

  # Creating admin tests

  test "should not create admin when logged out" do
    assert_difference("User.count", 0) do
{'fraction_non_alphanumeric': 0.08869771581133194, 'fraction_numerical': 0.004153070305547315, 'mean_word_length': 3.5815217391304346, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4328160', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1006, 'n_words': 325}