diff --git a/Gemfile b/Gemfile index f7077b1..966eb80 100644 --- a/Gemfile +++ b/Gemfile @@ -71,4 +71,5 @@ group :test do end gem "tailwindcss-rails", "~> 4.6" -gem "faker", "~> 3.8", group: :development +# Used for database seeding +gem "faker", "~> 3.8" diff --git a/config/ci.rb b/config/ci.rb index 6896b98..5618bf6 100644 --- a/config/ci.rb +++ b/config/ci.rb @@ -11,6 +11,7 @@ step "Security: Importmap vulnerability audit", "bin/importmap audit" step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error" step "Tests: Rails", "bin/rails test" + step "Tests: Seeds", "env RAILS_ENV=test bin/rails db:seed:replant" # Optional: Run system tests # step "Tests: System", "bin/rails test:system" diff --git a/db/seeds.rb b/db/seeds.rb index 460cc73..d8385d2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,30 +1,36 @@ -return unless Rails.env.development? - -programs = Program.create! [ { name: "Know Your Health" }, { name: "3D Wellness" } ] +def maybe(&block) + return unless Faker::Boolean.boolean -kyh, tdw = programs -ContentModule.levels.keys.each_with_index do |level, li| - [ kyh, tdw ].each do |program| - 2.times do |i| - mod = program.content_modules.create!(name: "#{program.name} #{level.humanize} Module #{i + 1}", level: level, position: i + 1) - mod.links.create!(title: "Survey #{i + 1}", url: "https://example.com/survey/#{program.id}-#{level}-#{i}", link_type: "survey", position: 1) - end - end + block.call end +programs = [ + Program.find_or_create_by!(name: "Know Your Health"), + Program.find_or_create_by!(name: "3D Wellness") +] User.find_or_create_by!(email_address: "admin@example.com") do |user| user.name = "Admin" user.password = "password" end -school = School.find_or_create_by!(name: "Example School") +# Production should not have any seeded data for the content or schools +return if Rails.env.production? -def maybe(&block) - return unless Faker::Boolean.boolean - - block.call +ContentModule.levels.keys.each do |level| + programs.each do |program| + 2.times do |i| + mod = program.content_modules.create!(name: "#{program.name} #{level.humanize} Module #{i + 1}", level: level, position: i + 1) + # TODO: Update this when the delegated types migration is completed + link = Link.new(title: "Survey #{i + 1}", url: "https://example.com/survey/#{program.id}-#{level}-#{i}", link_type: "survey", position: 1, content_module: mod) + mod.contents.create! contentable: link + end + end end + + +school = School.find_or_create_by!(name: "Example School") + teachers = 3.times.map do school.teachers.create!( name: Faker::Name.name,