Skip to content

Commit

Permalink
populate:users should create an admin user (doubleunion#796)
Browse files Browse the repository at this point in the history
When creating fake users for a development configuration, create an
admin user that can be used for testing admin tools.
  • Loading branch information
ItsElaineTime committed May 28, 2023
1 parent 876fa56 commit 1d9c508
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/tasks/populate.rake
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
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
created_admin = false

10.times do
user = create_fake_user
user.save

# Some parts of the app expect members to have an application with a valid processed_at date.
Expand All @@ -21,7 +31,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?

Expand Down

0 comments on commit 1d9c508

Please sign in to comment.