Browse Source

Improve DB seeding (#556)

* Improve DB seeding

* Don't seed LA Rent Ranges in test
pull/619/head
baarkerlounger 3 years ago committed by baarkerlounger
parent
commit
6139866565
  1. 2
      app/models/form_handler.rb
  2. 55
      db/seeds.rb
  3. 2
      lib/tasks/rent_ranges.rake

2
app/models/form_handler.rb

@ -20,7 +20,7 @@ private
forms = {} forms = {}
directories.each do |directory| directories.each do |directory|
Dir.glob("#{directory}/*.json").each do |form_path| Dir.glob("#{directory}/*.json").each do |form_path|
form_name = form_path.sub(".json", "").split("/")[-1] form_name = File.basename(form_path, ".json")
forms[form_name] = Form.new(form_path, form_name) forms[form_name] = Form.new(form_path, form_name)
end end
end end

55
db/seeds.rb

@ -6,7 +6,8 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first) # Character.create(name: 'Luke', movie: movies.first)
org = Organisation.create!( # rubocop:disable Rails/Output
org = Organisation.find_or_create_by!(
name: "DLUHC", name: "DLUHC",
address_line1: "2 Marsham Street", address_line1: "2 Marsham Street",
address_line2: "London", address_line2: "London",
@ -15,19 +16,43 @@ org = Organisation.create!(
other_stock_owners: "None", other_stock_owners: "None",
managing_agents: "None", managing_agents: "None",
provider_type: "LA", provider_type: "LA",
) ) do
User.create!( info = "Seeded DLUHC Organisation"
email: "test@example.com", if Rails.env.development?
password: "password", pp info
organisation: org, else
role: "data_provider", Rails.logger.info info
) end
end
User.create!( if Rails.env.development? && User.count.zero?
email: "coordinator@example.com", User.create!(
password: "password", email: "provider@example.com",
organisation: org, organisation: org,
role: "data_coordinator", role: "data_provider",
) )
AdminUser.create!(email: "admin@example.com", password: "password", phone: "000000000") User.create!(
email: "coordinator@example.com",
password: "password",
organisation: org,
role: "data_coordinator",
)
User.create!(
email: "support@example.com",
password: "password",
organisation: org,
role: "support",
)
pp "Seeded 3 dummy users"
end
if LaRentRange.count.zero? && !Rails.env.test?
Dir.glob("config/rent_range_data/*.csv").each do |path|
start_year = File.basename(path, ".csv")
Rake::Task["data_import:rent_ranges"].invoke(start_year, path)
end
end
# rubocop:enable Rails/Output

2
lib/tasks/rent_ranges.rake

@ -24,6 +24,6 @@ namespace :data_import do
) )
count += 1 count += 1
end end
pp "Created/updated #{count} records" unless Rails.env.test? pp "Created/updated #{count} LA Rent Range records" unless Rails.env.test?
end end
end end

Loading…
Cancel
Save