mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix user seeding
This commit is contained in:
@@ -40,7 +40,7 @@ def create_admin_user
|
||||
|
||||
load 'spree/user.rb'
|
||||
|
||||
if Spree::User.find_by(email:)
|
||||
if Spree::User.find_by(email: attributes[:email])
|
||||
say <<~TEXT
|
||||
|
||||
WARNING: There is already a user with the email: #{email},
|
||||
@@ -75,7 +75,7 @@ def read_user_attributes
|
||||
password = ENV.fetch("ADMIN_PASSWORD", "ofn123")
|
||||
email = ENV.fetch("ADMIN_EMAIL", "ofn@example.com")
|
||||
else
|
||||
Rails.logger.debug 'Create the admin user (press enter for defaults).'
|
||||
say 'Create the admin user (press enter for defaults).'
|
||||
email = prompt_for_admin_email
|
||||
password = prompt_for_admin_password
|
||||
end
|
||||
|
||||
12
db/seeds.rb
12
db/seeds.rb
@@ -8,26 +8,26 @@ require 'yaml'
|
||||
# We need mail_configuration to create a user account, because it sends a confirmation email.
|
||||
MailConfiguration.apply!
|
||||
|
||||
Rails.logger.debug "[db:seed] Seeding Countries"
|
||||
Rails.logger.info "[db:seed] Seeding Countries"
|
||||
unless Spree::Country.find_by(iso: ENV.fetch('DEFAULT_COUNTRY_CODE', nil))
|
||||
require File.join(File.dirname(__FILE__), 'default', 'countries')
|
||||
end
|
||||
country = Spree::Country.find_by(iso: ENV.fetch('DEFAULT_COUNTRY_CODE', nil))
|
||||
Rails.logger.debug { "Default country is #{country}" }
|
||||
Rails.logger.info { "Default country is #{country}" }
|
||||
|
||||
Rails.logger.debug { "[db:seed] Seeding states for #{country.name}" }
|
||||
Rails.logger.info { "[db:seed] Seeding states for #{country.name}" }
|
||||
states = YAML.load_file "db/default/spree/states.yml"
|
||||
states.each do |state|
|
||||
Rails.logger.debug { "State: #{state}" }
|
||||
Rails.logger.info { "State: #{state}" }
|
||||
unless Spree::State.find_by(name: state['name'])
|
||||
Spree::State.create!({ name: state['name'], abbr: state['abbr'], country: })
|
||||
end
|
||||
end
|
||||
|
||||
Rails.logger.debug "[db:seed] Seeding Zones"
|
||||
Rails.logger.info "[db:seed] Seeding Zones"
|
||||
require File.join(File.dirname(__FILE__), 'default', 'zones')
|
||||
|
||||
Rails.logger.debug "[db:seed] Seeding Users"
|
||||
Rails.logger.info "[db:seed] Seeding Users"
|
||||
require File.join(File.dirname(__FILE__), 'default', 'users')
|
||||
|
||||
DefaultStockLocation.find_or_create
|
||||
|
||||
Reference in New Issue
Block a user