<commit_before>require 'spec_helper'
require 'bcrypt'

describe User do
  it 'has fields' do
    expect(described_class).to have_fields :email, :password_hash, :password_salt, :token, :token_salt
  end

  describe 'password encryption' do
    let(:resource){described_class.create}

    context 'when password is not present' do
      it 'does nothing' do
        expect(resource.encrypt_password).to be_nil
      end
    end

    context 'when password is present' do
      let(:password){"<PASSWORD>"}

      it 'encrypts the password' do
        resource.password = password
        resource.encrypt_password

        expect(resource.password_hash).to eq BCrypt::Engine.hash_secret(password, resource.password_salt)
      end
    end
  end
end<commit_msg>Test virtualized password field.<commit_after>require 'spec_helper'
require 'bcrypt'

describe User do
  let(:resource){described_class.create}

  it 'has fields' do
    expect(described_class).to have_fields :email, :password_hash, :password_salt, :token, :token_salt
  end

  it 'does not have virtualized fields' do
    expect(described_class).to_not have_fields :password
  end

  context 'when password is not present' do
    describe 'password encryption' do
      it 'does nothing' do
        expect(resource.encrypt_password).to be_nil
      end
    end
  end

  context 'when password is present' do
    let(:password){"<PASSWORD>"}
    before{resource.password = password}

    describe 'password encryption' do
      it 'encrypts the password' do
        resource.encrypt_password

        expect(resource.password_hash).to eq BCrypt::Engine.hash_secret(password, resource.password_salt)
      end
    end

    describe 'virtualized password field' do
      it 'does not store passwords' do
        resource.save

        expect(described_class.find(resource.id).password).to be_nil
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0808940926024481, 'fraction_numerical': 0.0, 'mean_word_length': 3.372093023255814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3709874', 'n_tokens_mistral': 561, 'n_tokens_neox': 532, 'n_words': 158}