<commit_before>module AuthenticationWorkflow
  include Warden::Test::Helpers

  def quick_login_as(user)
    login_as user
  end

  def quick_login_as_admin
    admin_role = Spree::Role.find_or_create_by_name!('admin')
    admin_user = create(:user,
      :password => '<PASSWORD>',
      :password_confirmation => '<PASSWORD>',
      :remember_me => false,
      :persistence_token => '<PASSWORD>',
      :login => '<EMAIL>')

    admin_user.spree_roles << admin_role
    quick_login_as admin_user
    admin_user
  end

  def login_to_admin_section
    admin_role = Spree::Role.find_or_create_by_name!('admin')
    admin_user = create(:user,
      :password => '<PASSWORD>',
      :password_confirmation => '<PASSWORD>',
      :remember_me => false,
      :persistence_token => '<PASSWORD>',
      :login => '<EMAIL>')

    admin_user.spree_roles << admin_role
    quick_login_as admin_user
    visit spree.admin_path
  end

  # TODO: Should probably just rename this to create_user
  def create_enterprise_user( attrs = {} )
    new_user = create(:user, attrs)
    new_user.spree_roles = [] # for some reason unbeknown to me, this new user gets admin permissions by default.
    new_user.save
    new_user
  end

  def login_to_admin_as user
    quick_login_as user
    visit spree.admin_path
    #visit spree.admin_path
    #fill_in 'spree_user_email', :with => user.email
    #fill_in 'spree_user_password', :with => user.password
    #click_button 'Login'
  end

  def login_to_consumer_section
    user_role = Spree::Role.find_or_create_by_name!('user')
    user = create_enterprise_user({
      :email => '<EMAIL>',
      :password => '<PASSWORD>',
      :password_confirmation => '<PASSWORD>',
      :remember_me => false,
      :persistence_token => '<PASSWORD>',
      :login => '<EMAIL>'})

    user.spree_roles << user_role

    visit spree.login_path
    fill_in 'email', :with => '<EMAIL>'
    fill_in 'password', :with => '<PASSWORD>'
    click_button 'Login'
  end
end

RSpec.configure do |config|
  config.extend AuthenticationWorkflow, :type => :feature
end
<commit_msg>Remove code duplication in spec helper<commit_after>module AuthenticationWorkflow
  include Warden::Test::Helpers

  def quick_login_as(user)
    login_as user
  end

  def quick_login_as_admin
    admin_role = Spree::Role.find_or_create_by_name!('admin')
    admin_user = create(:user,
      :password => '<PASSWORD>',
      :password_confirmation => '<PASSWORD>',
      :remember_me => false,
      :persistence_token => '<PASSWORD>',
      :login => '<EMAIL>')

    admin_user.spree_roles << admin_role
    quick_login_as admin_user
    admin_user
  end

  def login_to_admin_section
    quick_login_as_admin
    visit spree.admin_path
  end

  # TODO: Should probably just rename this to create_user
  def create_enterprise_user( attrs = {} )
    new_user = create(:user, attrs)
    new_user.spree_roles = [] # for some reason unbeknown to me, this new user gets admin permissions by default.
    new_user.save
    new_user
  end

  def login_to_admin_as user
    quick_login_as user
    visit spree.admin_path
    #visit spree.admin_path
    #fill_in 'spree_user_email', :with => user.email
    #fill_in 'spree_user_password', :with => user.password
    #click_button 'Login'
  end

  def login_to_consumer_section
    user_role = Spree::Role.find_or_create_by_name!('user')
    user = create_enterprise_user({
      :email => '<EMAIL>',
      :password => '<PASSWORD>',
      :password_confirmation => '<PASSWORD>',
      :remember_me => false,
      :persistence_token => '<PASSWORD>',
      :login => '<EMAIL>'})

    user.spree_roles << user_role

    visit spree.login_path
    fill_in 'email', :with => '<EMAIL>'
    fill_in 'password', :with => '<PASSWORD>'
    click_button 'Login'
  end
end

RSpec.configure do |config|
  config.extend AuthenticationWorkflow, :type => :feature
end

{'fraction_non_alphanumeric': 0.11431513903192585, 'fraction_numerical': 0.0, 'mean_word_length': 3.625, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 66, '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': '3218404', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1284, 'n_words': 284}