From 117d5c6e592a11990ca9ed9e502bdec6cd5e5cb3 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Fri, 2 May 2025 17:35:24 +0200 Subject: [PATCH] Accounts always start with a "Cards" collection - Deleting the last collection, immediately creates a new "Cards" collection --- app/models/collection.rb | 9 +++++++++ app/models/first_run.rb | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/collection.rb b/app/models/collection.rb index 29e07a98b..9b74d8524 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -8,4 +8,13 @@ class Collection < ApplicationRecord has_many :events scope :alphabetically, -> { order("lower(name)") } + + after_destroy_commit :ensure_default_collection + + private + def ensure_default_collection + if Collection.count.zero? + Collection.create!(name: "Cards") + end + end end diff --git a/app/models/first_run.rb b/app/models/first_run.rb index cc48de7ad..88fc321f2 100644 --- a/app/models/first_run.rb +++ b/app/models/first_run.rb @@ -1,7 +1,10 @@ class FirstRun def self.create!(user_attributes) + user = User.member.create!(user_attributes) + Account.create!(name: "Fizzy") Closure::Reason.create_defaults - User.member.create!(user_attributes) + Collection.create!(name: "Cards", creator: user, all_access: true) + user end end