Using faker to populate my database with fake users, and I have a validation rule that ensures that usernames are unique and cannot be registered more than once.
When I run rake db: filling it never reaches 1000, it stops someday before it gets there, and because I use create! he shows me what I need to see that: Usernname is already registered.
My question is, how can I add a number to the username and every time it comes back around a number, it increases? Thus, no username will be the same.
eg.
John1 pete2 sally3 smith4 luke5 john6 sally7
etc.
or is there another way to make sure that no usernames appear more than once?
namespace :db do namespace :development do desc "Create user records in the development database." task :populate => :environment do require 'faker' 1000.times do User.create!( :username => Faker::Internet.user_name, :email => Faker::Internet.email, :password => "greatpasswordhuh" ) end end end end
Yours faithfully
source share