diff --git a/lib/tasks/invitations.rake b/lib/tasks/invitations.rake index 1accd05..e162f6f 100644 --- a/lib/tasks/invitations.rake +++ b/lib/tasks/invitations.rake @@ -2,12 +2,21 @@ namespace :invitations do desc "Generate invitations for all users" task :generate_for_all_users, [:amount_per_user] => :environment do |t, args| count = 0 + User.all.each do |user| - args[:amount_per_user].to_i.times do + amt_to_create = args[:amount_per_user].to_i - user.invitations.unused.count + next unless amt_to_create > 0 + amt_created = 0 + + amt_to_create.times do user.invitations << Invitation.create(user: user) count += 1 + amt_created += 1 end + + puts "Created #{amt_created} new invitations for #{user.address}" end - puts "Created #{count} new invitations" + + puts "---\nCreated #{count} new invitations overall" end end