From 9c307e322e71d3d3dae9340116588f94d44a15b4 Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Mon, 12 Oct 2026 20:46:05 -0400 Subject: [PATCH 1/4] fix: restructure seeds --- db/seeds.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 460cc73..4e85f23 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,21 +1,27 @@ -return unless Rails.env.development? -programs = Program.create! [ { name: "Know Your Health" }, { name: "3D Wellness" } ] +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 + +return if Rails.env.production? 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) + # TODO: Fix this mod.links.create!(title: "Survey #{i + 1}", url: "https://example.com/survey/#{program.id}-#{level}-#{i}", link_type: "survey", position: 1) end end end -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") From f4cdeb6478dd873557f00dcffab9a6a2dde54200 Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Wed, 14 Oct 2026 19:13:01 -0400 Subject: [PATCH 2/4] fix: update seeds --- db/seeds.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 4e85f23..d8385d2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,8 @@ +def maybe(&block) + return unless Faker::Boolean.boolean + + block.call +end programs = [ Program.find_or_create_by!(name: "Know Your Health"), @@ -8,15 +13,16 @@ user.password = "password" end +# Production should not have any seeded data for the content or schools return if Rails.env.production? -kyh, tdw = programs -ContentModule.levels.keys.each_with_index do |level, li| - [ kyh, tdw ].each do |program| +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: Fix this - mod.links.create!(title: "Survey #{i + 1}", url: "https://example.com/survey/#{program.id}-#{level}-#{i}", link_type: "survey", position: 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 @@ -25,12 +31,6 @@ school = School.find_or_create_by!(name: "Example School") -def maybe(&block) - return unless Faker::Boolean.boolean - - block.call -end - teachers = 3.times.map do school.teachers.create!( name: Faker::Name.name, From 1a4940a474a47225ed5c640e72ab02764f43defa Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Wed, 14 Oct 2026 19:21:35 -0400 Subject: [PATCH 3/4] fix: update ci to test seeding --- Gemfile | 4 +++- config/ci.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f7077b1..18b79a5 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,9 @@ group :development, :test do # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] gem "rubocop-rails-omakase", require: false + + # Used for database seeding + gem "faker", "~> 3.8" end group :development do @@ -71,4 +74,3 @@ group :test do end gem "tailwindcss-rails", "~> 4.6" -gem "faker", "~> 3.8", group: :development 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" From 91f2db0516ce35a4a27d3c62016981b552a54d4c Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Wed, 14 Oct 2026 20:17:31 -0400 Subject: [PATCH 4/4] fix: remove faker from gem group so it is available on staging --- Gemfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 18b79a5..966eb80 100644 --- a/Gemfile +++ b/Gemfile @@ -56,9 +56,6 @@ group :development, :test do # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] gem "rubocop-rails-omakase", require: false - - # Used for database seeding - gem "faker", "~> 3.8" end group :development do @@ -74,3 +71,5 @@ group :test do end gem "tailwindcss-rails", "~> 4.6" +# Used for database seeding +gem "faker", "~> 3.8"