Files
openfoodnetwork/lib/tasks/sample_data/user_factory.rb
2020-02-22 11:06:51 +00:00

41 lines
817 B
Ruby

require "tasks/sample_data/logging"
class UserFactory
include Logging
def create_samples
log "Creating users:"
usernames.map { |name|
create_user(name)
}.to_h
end
private
def usernames
[
"Manel Super Admin",
"Penny Profile",
"Fred Farmer",
"Freddy Shop Farmer",
"Fredo Hub Farmer",
"Mary Retailer",
"Maryse Private",
"Jane Customer"
]
end
def create_user(name)
email = "#{name.downcase.tr(' ', '.')}@example.org"
password = Spree::User.friendly_token
log "- #{email}"
user = Spree::User.create_with(
password: password,
password_confirmation: password,
confirmation_sent_at: Time.zone.now,
confirmed_at: Time.zone.now
).find_or_create_by!(email: email)
[name, user]
end
end