From a8a64a2384615487be4671e1c02bd56872ff3376 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 16 Jun 2025 15:18:31 -0400 Subject: [PATCH] Link the seeds up to the signal_id fixture data --- app/models/signup.rb | 15 +++++++------ bin/dev | 2 -- bin/setup | 9 ++++++-- db/seeds.rb | 49 ++++++++++++++++++++++++++++++++--------- db/seeds/37signals.rb | 8 +++---- db/seeds/first-run.rb | 1 - db/seeds/honcho.rb | 16 +++++++------- test/fixtures/users.yml | 2 +- 8 files changed, 66 insertions(+), 36 deletions(-) delete mode 100644 db/seeds/first-run.rb diff --git a/app/models/signup.rb b/app/models/signup.rb index 194debfa8..494dc883a 100644 --- a/app/models/signup.rb +++ b/app/models/signup.rb @@ -26,12 +26,12 @@ class Signup super end - def process + def process(destroy_existing_tenant: false) return false unless valid? create_signal_identity create_queenbee_account - create_tenant + create_tenant(destroy_existing_tenant:) true rescue => error @@ -44,6 +44,10 @@ class Signup false end + def tenant_name + @tenant_name ||= signal_account.subdomain + end + private def create_signal_identity unless signal_identity.present? @@ -60,7 +64,8 @@ class Signup end end - def create_tenant(&block) + def create_tenant(destroy_existing_tenant: false, &block) + ApplicationRecord.destroy_tenant(tenant_name) if destroy_existing_tenant ApplicationRecord.create_tenant(tenant_name) do @account = Account.create_with_admin_user(queenbee_id: queenbee_account.id) @account.setup_basic_template @@ -126,8 +131,4 @@ class Signup def request_attributes { remote_address: Current.ip_address, user_agent: Current.user_agent, referrer: Current.referrer } end - - def tenant_name - @tenant_name ||= signal_account.subdomain - end end diff --git a/bin/dev b/bin/dev index 4099edaa0..e5fc62f6c 100755 --- a/bin/dev +++ b/bin/dev @@ -2,10 +2,8 @@ echo "Access with david@37signals.com / secret123456 on http://37signals.fizzy.localhost:3006" echo "Access with david@37signals.com / secret123456 on http://honcho.fizzy.localhost:3006" -echo "Access first run on http://first-run.fizzy.localhost:3006" if [ -f tmp/solid-queue.txt ]; then - # see also config/environments/development.rb export SOLID_QUEUE_IN_PUMA=1 fi diff --git a/bin/setup b/bin/setup index c7223d499..61727ea2e 100755 --- a/bin/setup +++ b/bin/setup @@ -7,8 +7,13 @@ system("gem install bundler --conservative") system("bundle check") || system!("bundle install") puts "\n== Preparing database ==" -system! "bin/rails db:prepare" -system! "bin/rails db:reset" if ARGV.include?("--reset") +if ARGV.include?("--reset") + system! "bin/rails db:drop db:create db:schema:load db:prepare" + system! "bin/rails db:fixtures:load" # load signal id fixtures before running fizzy seeds + system! "bin/rails db:seed" +else + system! "bin/rails db:prepare" +end puts "\n== Removing old logs and tempfiles ==" system! "bin/rails log:clear tmp:clear" diff --git a/db/seeds.rb b/db/seeds.rb index 9af00fe66..a04ee160e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,24 +7,52 @@ def seed_account(name) puts " #{elapsed.round(2)} sec" end -def create_tenant(name) - ApplicationRecord.destroy_tenant name - ApplicationRecord.create_tenant name - ApplicationRecord.current_tenant = name +def create_tenant(signal_account_name) + signal_account = SignalId::Account.find_by_product_and_name!("fizzy", signal_account_name) + tenant_name = signal_account.subdomain + + ApplicationRecord.destroy_tenant tenant_name + ApplicationRecord.create_tenant(tenant_name) do + account = Account.create_with_admin_user(queenbee_id: signal_account.queenbee_id) + account.setup_basic_template + end + + ApplicationRecord.current_tenant = tenant_name end -def create_first_run(name, email_address, password: "secret123456") - FirstRun.create!(name:, email_address:, password:) +def find_or_create_user(full_name, email_address) + SignalId::Database.on_master do + unless signal_identity = SignalId::Identity.find_by_email_address(email_address) + signal_identity = SignalId::Identity.create!( + name: full_name, + email_address: email_address, + username: email_address, + password: "secret123456" + ) + end + + signal_account = Account.first.signal_account + signal_user = SignalId::User.find_or_create_by!(identity: signal_identity, account: signal_account) + + if user = User.find_by(signal_user_id: signal_user.id) + user.password = "secret123456" + user.save! + user + else + User.create!( + signal_user_id: signal_user.id, + name: signal_identity.name, + email_address: signal_identity.email_address, + password: "secret123456" + ) + end + end end def login_as(user) Current.session = user.sessions.create end -def create_user(name, email_address, password: "secret123456") - User.create!(name:, email_address:, password:) -end - def create_collection(name, creator: Current.user, all_access: true, access_to: []) Collection.create!(name:, creator:, all_access:).tap { it.accesses.grant_to(access_to) } end @@ -36,4 +64,3 @@ end # Seed accounts seed_account "37signals" seed_account "honcho" -seed_account "first-run" diff --git a/db/seeds/37signals.rb b/db/seeds/37signals.rb index 432030bbc..2bc322fdc 100644 --- a/db/seeds/37signals.rb +++ b/db/seeds/37signals.rb @@ -1,10 +1,10 @@ create_tenant "37signals" -david = create_first_run "David Heinemeier Hansson", "david@37signals.com" -login_as david +david = find_or_create_user "David Heinemeier Hansson", "david@37signals.com" +jz = find_or_create_user "Jason Zimdars", "jz@37signals.com" +kevin = find_or_create_user "Kevin Mcconnell", "kevin@37signals.com" -jz = create_user "Jason Zimdars", "jz@37signals.com" -kevin = create_user "Kevin Mcconnell", "kevin@37signals.com" +login_as david create_collection("Fizzy", access_to: [ jz, kevin ]).tap do |fizzy| create_card("Prepare sign-up page", description: "We need to do this before the launch.", collection: fizzy) diff --git a/db/seeds/first-run.rb b/db/seeds/first-run.rb deleted file mode 100644 index e6df219d9..000000000 --- a/db/seeds/first-run.rb +++ /dev/null @@ -1 +0,0 @@ -create_tenant "first-run" diff --git a/db/seeds/honcho.rb b/db/seeds/honcho.rb index 34599c600..939dc9147 100644 --- a/db/seeds/honcho.rb +++ b/db/seeds/honcho.rb @@ -1,15 +1,15 @@ -create_tenant "honcho" +create_tenant "Honcho" + +david = find_or_create_user "David Heinemeier Hansson", "david@37signals.com" +jason = find_or_create_user "Jason Zimdars", "jz@37signals.com" +kevin = find_or_create_user "Kevin McConnell", "kevin@37signals.com" +jorge = find_or_create_user "Jorge Manrubia", "jorge@37signals.com" +mike = find_or_create_user "Mike Dalessio", "mike@37signals.com" -david = create_first_run "David Heinemeier Hansson", "david@37signals.com" login_as david -jason = create_user "Jason Zimdars", "jz@37signals.com" -kevin = create_user "Kevin Mcconnell", "kevin@37signals.com" -sarah = create_user "Sarah Johnson", "sarah@37signals.com" -mike = create_user "Mike Peterson", "mike@37signals.com" - # Array of authors for random assignment -authors = [ david, jason, kevin, sarah, mike ] +authors = [ david, jason, kevin, jorge, mike ] # Card titles for reuse across collections card_titles = [ diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index dc13feca0..3339d12d6 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -12,7 +12,7 @@ jz: email_address: jz@37signals.com password_digest: <%= digest %> role: member - signal_user: 37s_fizzy_jz + signal_user: 37s_fizzy_jzimdars kevin: name: Kevin