<commit_before># This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
require 'yaml'

# -- Spree
unless Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
  puts "[db:seed] Seeding Spree"
  Spree::Core::Engine.load_seed if defined?(Spree::Core)
  Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
end

country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
puts "Country is #{country.to_s}"

puts "[db:seed] loading states yaml"
states = YAML::load_file "db/default/spree/states.yml"
puts "States: #{states.to_s}"

# -- Seeding States
puts "[db:seed] Seeding states for " + country.name

states.each do |state|
  puts "State: " + state.to_s

  unless Spree::State.find_by_name(state['name'])
    Spree::State.create!(
      { name: state['name'], abbr: state['abbr'], country: country },
      without_protection: true
    )
  end
end

def create_mail_method
  Spree::MailMethod.destroy_all

  CreateMailMethod.new(
    environment: Rails.env,
    preferred_enable_mail_delivery: true,
    preferred_mail_host: ENV.fetch('MAIL_HOST'),
    preferred_mail_domain: ENV.fetch('MAIL_DOMAIN'),
    preferred_mail_port: ENV.fetch('MAIL_PORT'),
    preferred_mail_auth_type: 'login',
    preferred_smtp_username: ENV.fetch('SMTP_USERNAME'),
    preferred_smtp_password: ENV.fetch('SMTP_PASSWORD'),
    preferred_secure_connection_type: ENV.fetch('MAIL_SECURE_CONNECTION', 'None'),
    preferred_mails_from: ENV.fetch('MAILS_FROM', "no-reply@#{ENV.fetch('MAIL_DOMAIN')}"),
    preferred_mail_bcc: ENV.fetch('MAIL_BCC', ''),
    preferred_intercept_email: ''
  ).call
end

create_mail_method

spree_user = Spree::User.first
spree_user && spree_user.confirm!
<commit_msg>Create MailMethod before User when seeding<commit_after># This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
require 'yaml'

def create_mail_method
  Spree::MailMethod.destroy_all

  CreateMailMethod.new(
    environment: Rails.env,
    preferred_enable_mail_delivery: true,
    preferred_mail_host: ENV.fetch('MAIL_HOST'),
    preferred_mail_domain: ENV.fetch('MAIL_DOMAIN'),
    preferred_mail_port: ENV.fetch('MAIL_PORT'),
    preferred_mail_auth_type: 'login',
    preferred_smtp_username: ENV.fetch('SMTP_USERNAME'),
    preferred_smtp_password: ENV.fetch('<PASSWORD>'),
    preferred_secure_connection_type: ENV.fetch('MAIL_SECURE_CONNECTION', 'None'),
    preferred_mails_from: ENV.fetch('MAILS_FROM', "no-reply@#{ENV.fetch('MAIL_DOMAIN')}"),
    preferred_mail_bcc: ENV.fetch('MAIL_BCC', ''),
    preferred_intercept_email: ''
  ).call
end

# We need a mail method to create a user account, because it sends a
# confirmation email.
create_mail_method

# -- Spree
unless Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
  puts "[db:seed] Seeding Spree"
  Spree::Core::Engine.load_seed if defined?(Spree::Core)
  Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
end

country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
puts "Country is #{country.to_s}"

puts "[db:seed] loading states yaml"
states = YAML::load_file "db/default/spree/states.yml"
puts "States: #{states.to_s}"

# -- Seeding States
puts "[db:seed] Seeding states for " + country.name

states.each do |state|
  puts "State: " + state.to_s

  unless Spree::State.find_by_name(state['name'])
    Spree::State.create!(
      { name: state['name'], abbr: state['abbr'], country: country },
      without_protection: true
    )
  end
end

spree_user = Spree::User.first
spree_user && spree_user.confirm!

{'fraction_non_alphanumeric': 0.12834791832405198, 'fraction_numerical': 0.0, 'mean_word_length': 5.4040747028862475, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4754786', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1315, 'n_words': 283}