2018-07-02 18:40:09 +02:00
|
|
|
CheckLog.destroy_all
|
2018-06-04 14:02:15 +02:00
|
|
|
Notification.destroy_all
|
|
|
|
Check.destroy_all
|
|
|
|
User.destroy_all
|
|
|
|
|
|
|
|
user1 = User.create!(
|
|
|
|
email: "colin@example.org",
|
|
|
|
password: "password",
|
|
|
|
tos_accepted: true,
|
2018-07-03 19:46:39 +02:00
|
|
|
confirmed_at: Time.now,
|
|
|
|
locale: :fr,
|
|
|
|
)
|
|
|
|
|
|
|
|
user2 = User.create!(
|
|
|
|
email: "colin+en@example.org",
|
|
|
|
password: "password",
|
|
|
|
tos_accepted: true,
|
|
|
|
confirmed_at: Time.now,
|
|
|
|
locale: :en,
|
2018-06-04 14:02:15 +02:00
|
|
|
)
|
|
|
|
|
2018-07-04 19:05:52 +02:00
|
|
|
users = [user1, user2]
|
|
|
|
|
2018-06-04 14:02:15 +02:00
|
|
|
check_chexpire_org = Check.create!(
|
|
|
|
user: user1,
|
|
|
|
kind: :domain,
|
|
|
|
domain: "chexpire.org",
|
|
|
|
domain_expires_at: 1.week.from_now,
|
|
|
|
domain_updated_at: 6.months.ago,
|
|
|
|
domain_created_at: Time.new(2016, 8, 4, 12, 15, 1),
|
|
|
|
comment: "The date are fake, this is a seed !",
|
|
|
|
vendor: "Some random registrar",
|
|
|
|
)
|
|
|
|
|
|
|
|
check_chexpire_org_error = Check.create!(
|
|
|
|
user: user1,
|
|
|
|
kind: :domain,
|
2018-07-03 19:46:39 +02:00
|
|
|
domain: "chexpire-error.org",
|
2018-06-04 14:02:15 +02:00
|
|
|
domain_expires_at: 1.week.from_now,
|
|
|
|
domain_updated_at: 6.months.ago,
|
|
|
|
domain_created_at: Time.new(2016, 8, 4, 12, 15, 1),
|
|
|
|
comment: "The date are fake, this is a seed !",
|
|
|
|
vendor: "Some random registrar",
|
|
|
|
last_run_at: 20.minutes.ago,
|
2018-07-04 19:05:52 +02:00
|
|
|
created_at: 3.weeks.ago,
|
2018-06-04 14:02:15 +02:00
|
|
|
)
|
|
|
|
|
2018-07-02 18:40:09 +02:00
|
|
|
ssl_check_chexpire_org = Check.create!(
|
|
|
|
user: user1,
|
|
|
|
kind: :ssl,
|
|
|
|
domain: "www.chexpire.org",
|
|
|
|
domain_expires_at: 1.week.from_now,
|
|
|
|
domain_updated_at: 6.months.ago,
|
|
|
|
domain_created_at: Time.new(2016, 8, 4, 12, 15, 1),
|
|
|
|
comment: "The date are fake, this is a seed !",
|
|
|
|
vendor: "Some random registrar",
|
|
|
|
)
|
|
|
|
|
|
|
|
ssl_check_chexpire_org_error = Check.create!(
|
|
|
|
user: user1,
|
|
|
|
kind: :ssl,
|
2018-07-03 19:46:39 +02:00
|
|
|
domain: "chexpire-error.org",
|
2018-07-02 18:40:09 +02:00
|
|
|
domain_expires_at: 1.week.from_now,
|
|
|
|
domain_updated_at: 6.months.ago,
|
|
|
|
domain_created_at: Time.new(2016, 8, 4, 12, 15, 1),
|
|
|
|
comment: "The date are fake, this is a seed !",
|
|
|
|
vendor: "Some random registrar",
|
|
|
|
last_run_at: 20.minutes.ago,
|
|
|
|
last_success_at: 4.days.ago,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-07-04 19:05:52 +02:00
|
|
|
def check_factory(users)
|
2018-07-03 19:46:39 +02:00
|
|
|
ext = %w[com net org fr].sample
|
|
|
|
word = (0...rand(4..12)).map { (97 + rand(26)).chr }.join
|
|
|
|
|
2018-07-04 19:05:52 +02:00
|
|
|
Check.new(
|
|
|
|
user: users.sample,
|
2018-07-03 19:46:39 +02:00
|
|
|
kind: Check.kinds.keys.sample,
|
|
|
|
domain: "#{word}.#{ext}",
|
2018-07-04 12:33:50 +02:00
|
|
|
domain_expires_at: rand(8..300).days.from_now,
|
2018-07-03 19:46:39 +02:00
|
|
|
domain_updated_at: rand(1..300).days.ago,
|
|
|
|
domain_created_at: rand(301..3000).days.ago,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-07-04 19:05:52 +02:00
|
|
|
100.times do |i|
|
|
|
|
check_factory(users).save!
|
|
|
|
end
|
|
|
|
|
|
|
|
# checks with error
|
|
|
|
10.times do |i|
|
|
|
|
check_factory(users).update_attributes(
|
|
|
|
created_at: rand(1..300).days.ago,
|
|
|
|
last_run_at: 4.hours.ago,
|
|
|
|
last_success_at: rand(10...100).days.ago,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-06-04 14:02:15 +02:00
|
|
|
Notification.create!(
|
|
|
|
check: check_chexpire_org,
|
2018-06-05 22:44:48 +02:00
|
|
|
interval: 15,
|
2018-06-04 14:02:15 +02:00
|
|
|
channel: :email,
|
|
|
|
recipient: "colin@example.org",
|
|
|
|
status: :pending,
|
|
|
|
)
|
|
|
|
|
|
|
|
Notification.create!(
|
|
|
|
check: check_chexpire_org_error,
|
2018-06-05 22:44:48 +02:00
|
|
|
interval: 15,
|
2018-06-04 14:02:15 +02:00
|
|
|
channel: :email,
|
|
|
|
recipient: "colin@example.org",
|
|
|
|
status: :pending,
|
|
|
|
)
|
|
|
|
|
2018-07-02 18:40:09 +02:00
|
|
|
Notification.create!(
|
|
|
|
check: ssl_check_chexpire_org,
|
|
|
|
interval: 15,
|
|
|
|
channel: :email,
|
|
|
|
recipient: "colin@example.org",
|
|
|
|
status: :pending,
|
|
|
|
)
|
|
|
|
|
|
|
|
Notification.create!(
|
|
|
|
check: ssl_check_chexpire_org_error,
|
|
|
|
interval: 15,
|
|
|
|
channel: :email,
|
|
|
|
recipient: "colin@example.org",
|
|
|
|
status: :pending,
|
|
|
|
)
|
|
|
|
|
2018-06-04 14:02:15 +02:00
|
|
|
puts "\e[0;32mDone 👌\e[0m"
|
|
|
|
puts " "
|
|
|
|
puts "--------------------"
|
|
|
|
puts "Users: #{User.count}"
|
|
|
|
puts "Checks: #{Check.count}"
|
|
|
|
puts "Notifications: #{Notification.count}"
|