Skip to content

Instantly share code, notes, and snippets.

@milushov
Last active August 29, 2015 14:16
Show Gist options
  • Save milushov/678299fd7266b9c387c0 to your computer and use it in GitHub Desktop.
Save milushov/678299fd7266b9c387c0 to your computer and use it in GitHub Desktop.
last_id = 42
User.destroy_all "id > #{last_id}"
require 'csv'
file = "#{Rails.root}/users.csv"
passwords = {}
rate = Rate.find_by_name('Unlimited')
(1..200).each do |i|
u = User.create! do |user|
passwords[i] = (1..8).map{ [*'0'..'9', *'a'..'z'].sample }.join
user.email = "test-#{i}@conomy.ru"
user.name = 'Test'
user.surname = 'Test'
user.password = passwords[i]
end
user_rate = UserRate.new(
rate_id: rate.id,
ends_at: Time.parse('2020-01-01'),
capacity: 20
)
u.user_rates.push(user_rate)
end
CSV.open(file, 'w') do |csv|
User.where("id > #{last_id}").order('id asc').each_with_index do |u, i|
csv << [u.email, passwords[i+1]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment