Skip to content

Commit

Permalink
Fix user seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
mkllnk committed Jan 15, 2025
1 parent 1f0f963 commit c375c9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions db/default/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -76,7 +76,7 @@ def read_user_attributes
password = ENV.fetch("ADMIN_PASSWORD", "ofn123")
email = ENV.fetch("ADMIN_EMAIL", "[email protected]")
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
Expand Down
14 changes: 7 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
# We need mail_configuration to create a user account, because it sends a confirmation email.
MailConfiguration.apply!

Rails.logger.debug "[db:seed] Seeding Roles"
Rails.logger.info "[db:seed] Seeding Roles"
Spree::Role.where(name: "admin").first_or_create
Spree::Role.where(name: "user").first_or_create

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
Expand Down

0 comments on commit c375c9a

Please sign in to comment.