From c3bcb10c2b036ad8e0c190dbd99d981c6709d9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jul 2019 21:41:53 +0200 Subject: [PATCH] Make WebSection seeds idempotent Each time we were loading the seeds file, more web sections were created. On production it meant running `db:seeds` several times created the records even if they already existed. During the test, it meant 5 more records were created before every test, so after ending a test run, thousands of records existed, making banner tests very slow. --- db/seeds.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 37599fd0c..9ae6f7bf3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,11 +9,11 @@ end Setting.reset_defaults -WebSection.create(name: "homepage") -WebSection.create(name: "debates") -WebSection.create(name: "proposals") -WebSection.create(name: "budgets") -WebSection.create(name: "help_page") +WebSection.where(name: "homepage").first_or_create +WebSection.where(name: "debates").first_or_create +WebSection.where(name: "proposals").first_or_create +WebSection.where(name: "budgets").first_or_create +WebSection.where(name: "help_page").first_or_create # Default custom pages load Rails.root.join("db", "pages.rb")