<commit_before>RSpec.describe Spree::User, type: :model do

  before(:all) { Spree::Role.create name: 'admin' }

  it '#admin?' do
    expect(create(:admin_user).admin?).to be true
    expect(create(:user).admin?).to be false
  end

  it 'generates the reset password token' do
    user = build(:user)
    expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
    user.send_reset_password_instructions
    expect(user.reset_password_token).not_to be_nil
  end

  context '#destroy' do
    it 'will soft delete' do
      order = build(:order, completed_at: Time.now)
      order.save
      user = order.user
      user.destroy
      expect(Spree::User.find_by_id(user.id)).to be_nil
      expect(Spree::User.with_deleted.find_by_id(user.id).id).to eq(user.id)
      expect(Spree::User.with_deleted.find_by_id(user.id).orders.first).to eq(order)

      expect(Spree::Order.find_by_user_id(user.id)).not_to be_nil
      expect(Spree::Order.where(user_id: user.id).first).to eq(order)
    end

    it 'will allow users to register later with same email address as previously deleted account' do
      user1 = build(:user)
      user1.save
<commit_msg>Fixes Spree::User model specs for the new fixed behaviour of Spree::UserMethods<commit_after>RSpec.describe Spree::User, type: :model do

  before(:all) { Spree::Role.create name: 'admin' }

  it '#admin?' do
    expect(create(:admin_user).admin?).to be true
    expect(create(:user).admin?).to be false
  end

  it 'generates the reset password token' do
    user = build(:user)
    expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
    user.send_reset_password_instructions
    expect(user.reset_password_token).not_to be_nil
  end

  context '#destroy' do
    it 'will soft delete with uncompleted orders' do
      order = build(:order)
      order.save
      user = order.user
      user.destroy
      expect(Spree::User.find_by_id(user.id)).to be_nil
      expect(Spree::User.with_deleted.find_by_id(user.id).id).to eq(user.id)
      expect(Spree::User.with_deleted.find_by_id(user.id).orders.first).to eq(order)

      expect(Spree::Order.find_by_user_id(user.id)).not_to be_nil
      expect(Spree::Order.where(user_id: user.id).first).to eq(order)
    end

    it 'will not soft delete with completed orders' do
      order = build(:order, completed_at: Time.now)
      order.save
      user = order.user
      expect { user.destroy }.to raise_error(Spree::Core::DestroyWithOrdersError)
    end

    it 'will allow users to register later with same email address as previously deleted account' do
      user1 = build(:user)
      user1.save

{'fraction_non_alphanumeric': 0.12067079839591688, 'fraction_numerical': 0.0014582573824279985, 'mean_word_length': 3.8056042031523645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7524163', 'n_tokens_mistral': 905, 'n_tokens_neox': 887, 'n_words': 200}