Create MailMethod before User when seeding

This commit is contained in:
Maikel Linke
2018-09-17 15:31:42 +10:00
parent 9dcc683dc0
commit af1ac333df

View File

@@ -2,6 +2,29 @@
# 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('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
# 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"
@@ -30,26 +53,5 @@ states.each do |state|
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!