Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a9ed3d2

Browse files
committedMay 28, 2023
populate:users should create an admin user (doubleunion#796)
When creating fake users for a development configuration, create an admin user that can be used for testing admin tools.
1 parent 876fa56 commit a9ed3d2

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed
 

‎lib/tasks/populate.rake

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
def create_fake_user(state = nil)
2+
unless state
3+
states = User.state_machine.states.map(&:name).map(&:to_s)
4+
state = states.sample
5+
end
6+
7+
user = User.new
8+
9+
user.username = Faker::Internet.user_name
10+
user.name = Faker::Name.name
11+
user.email = Faker::Internet.email
12+
user.state = state
13+
14+
return user
15+
end
16+
117
namespace :populate do
218
desc "Populate users in development"
319
task users: :environment do
420
raise "development only" unless Rails.env.development?
521

6-
10.times do
7-
states = User.state_machine.states.map(&:name).map(&:to_s)
8-
9-
user = User.new
10-
11-
user.username = Faker::Internet.user_name
12-
user.name = Faker::Name.name
13-
user.email = Faker::Internet.email
14-
user.state = states.sample
22+
created_admin = false
1523

24+
10.times do
25+
user = create_fake_user
1626
user.save
1727

1828
# Some parts of the app expect members to have an application with a valid processed_at date.
@@ -21,7 +31,12 @@ namespace :populate do
2131
user.save!
2232
end
2333
end
34+
35+
admin_user = create_fake_user("voting_member")
36+
admin_user.make_admin!
37+
admin_user.save
2438
end
39+
2540
task :user, [:username, :name, :email, :state] => :environment do |t, args|
2641
raise "username not provided" unless !!args.username && !args.username.empty?
2742

0 commit comments

Comments
 (0)
Please sign in to comment.