<commit_before>require 'rails_helper'

describe Util::UserDbManager do
  let(:username) { 'testuser' }
  let(:original_password) { '<PASSWORD>' }
  let(:dummy_password) { ENV['UNCONFIRMED_USER_PASSWORD'] }

  subject { described_class.new }

  context 'when managing user accounts' do
    it 'should create initial db account that user cannot access' do
      user=User.create({:last_name=>'lastname',:first_name=>'firstname',:email=>'<EMAIL>',:username=>username,:password=><PASSWORD>,:skip_password_validation=>true})
      # make sure user account doesn't already exist
      subject.remove_user(user)
      expect(subject.user_account_exists?(user)).to be(false)
      user.create_unconfirmed
      expect(user.unencrypted_password).to eq(<PASSWORD>)

      expect(described_class.new.user_account_exists?(user)).to be(true)
      user_rec=described_class.new.pub_con.execute("SELECT * FROM pg_catalog.pg_user where usename = '#{user.username}'")
      expect(user_rec.count).to eq(1)
      expect(user.unencrypted_password).to eq(<PASSWORD>)
      # once user is confirmed, the unencrypted_password should be set to nil (only used to set pwd for db acct)
      user.confirm
      expect(user.unencrypted_password).to eq(nil)<commit_msg>Make the UserDbManager responsible for creating user accounts<commit_after>require 'rails_helper'

describe Util::UserDbManager do
  let(:username) { 'testuser' }
  let(:original_password) { '<PASSWORD>' }
  let(:dummy_password) { ENV['UN<PASSWORD>'] }

  subject { described_class.new }

  context 'when managing user accounts' do
    it 'should create initial db account that user cannot access' do
      user=User.create({:last_name=>'lastname',:first_name=>'firstname',:email=>'<EMAIL>',:username=>username,:password=><PASSWORD>,:skip_password_validation=>true})
      # make sure user account doesn't already exist
      subject.remove_user(user)
      expect(subject.user_account_exists?(user)).to be(false)
      Util::UserDbManager.new.create_user_account(user)
      expect(user.unencrypted_password).to eq(<PASSWORD>)

      expect(described_class.new.user_account_exists?(user)).to be(true)
      user_rec=described_class.new.pub_con.execute("SELECT * FROM pg_catalog.pg_user where usename = '#{user.username}'")
      expect(user_rec.count).to eq(1)
      expect(user.unencrypted_password).to eq(<PASSWORD>)
      # once user is confirmed, the unencrypted_password should be set to nil (only used to set pwd for db acct)
      user.confirm
      expect(user.unencrypted_password).to eq(nil)
{'fraction_non_alphanumeric': 0.12308297286669288, 'fraction_numerical': 0.0007864726700747149, 'mean_word_length': 4.985882352941177, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 26, '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': '2971485', 'n_tokens_mistral': 790, 'n_tokens_neox': 772, 'n_words': 164}