From 62b646eb3927464c57fc993df65d88651326119c Mon Sep 17 00:00:00 2001 From: Elaine Knight Date: Sat, 27 May 2023 19:27:34 -0700 Subject: [PATCH] populate:users should create an admin user (#796) When creating fake users for a development configuration, create an admin user that can be used for testing admin tools. --- lib/tasks/populate.rake | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/tasks/populate.rake b/lib/tasks/populate.rake index 09ab53b9..c75fa5d7 100644 --- a/lib/tasks/populate.rake +++ b/lib/tasks/populate.rake @@ -1,18 +1,26 @@ +def create_fake_user(state = nil) + unless state + states = User.state_machine.states.map(&:name).map(&:to_s) + state = states.sample + end + + user = User.new + + user.username = Faker::Internet.user_name + user.name = Faker::Name.name + user.email = Faker::Internet.email + user.state = state + + return user +end + namespace :populate do desc "Populate users in development" task users: :environment do raise "development only" unless Rails.env.development? 10.times do - states = User.state_machine.states.map(&:name).map(&:to_s) - - user = User.new - - user.username = Faker::Internet.user_name - user.name = Faker::Name.name - user.email = Faker::Internet.email - user.state = states.sample - + user = create_fake_user user.save # Some parts of the app expect members to have an application with a valid processed_at date. @@ -21,7 +29,12 @@ namespace :populate do user.save! end end + + admin_user = create_fake_user("voting_member") + admin_user.make_admin! + admin_user.save end + task :user, [:username, :name, :email, :state] => :environment do |t, args| raise "username not provided" unless !!args.username && !args.username.empty?