-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathseeds.rb
96 lines (82 loc) · 2.86 KB
/
seeds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
require "faker"
require "factory_bot"
FactoryBot.find_definitions
organisation = Organisation.create!(
name: "UKTI Education", service_email: "[email protected]",
)
empty_organisation = Organisation.create!(
name: "Academy for Social Justice Commissioning", service_email: "[email protected]",
)
FactoryBot.create(:user, :super_admin, email: "[email protected]", password: "password")
FactoryBot.create(:user, :confirm_all_memberships, :super_admin,
email: "[email protected]", password: "password", organisations: [organisation, empty_organisation])
3.times do
FactoryBot.create(:user, :confirm_all_memberships, organisations: [organisation])
end
2.times do
FactoryBot.create(:user, :unconfirmed, organisations: [organisation])
end
# Location with no IP addresses
Location.create!(
address: "The White Chapel Building, London",
postcode: "E1 8QS",
organisation_id: organisation.id,
)
location_one = Location.create!(
address: "Momentum Centre, London",
postcode: "SE1 0SX",
organisation_id: organisation.id,
)
location_two = Location.create!(
address: "136 Southwark Street, London",
postcode: "E3 3EH",
organisation_id: organisation.id,
)
10.times do
Ip.create!(
address: Faker::Internet.unique.public_ip_v4_address,
location: location_one,
created_at: [Time.zone.now, (Time.zone.now - 1.day)].sample,
)
end
ip = FactoryBot.create(:ip, address: Faker::Internet.unique.public_ip_v4_address,
location: location_one,
created_at: Time.zone.now - 10.days)
FactoryBot.create_list(:session, 50,
success: true,
siteIP: ip.address,
start: Time.zone.now,
mac: Faker::Internet.mac_address,
ap: Faker::Internet.mac_address,
username: SecureRandom.alphanumeric(6).downcase)
FactoryBot.create_list(:session, 20,
success: false,
siteIP: ip.address,
start: Time.zone.now)
3.times do
Ip.create!(
address: Faker::Internet.unique.public_ip_v4_address,
location: location_two,
)
end
location_one.ips.each_with_index do |location_one_ip, index|
Session.create(
start: (Time.zone.now - (index + 5).day).to_s,
success: index.even?,
username: "Gerry",
siteIP: location_one_ip.address,
)
end
location_two.ips.each_with_index do |location_two_ip, index|
Session.create(
start: (Time.zone.now - index.day).to_s,
success: index.even?,
username: "Garry",
siteIP: location_two_ip.address,
)
end
Organisation.all.find_each do |org|
org.update(cba_enabled: false)
end