Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate:users should create an admin user (#796) #797

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/tasks/populate.rake
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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?

Expand Down