Link the seeds up to the signal_id fixture data

This commit is contained in:
Mike Dalessio
2025-06-16 15:18:31 -04:00
parent 4d7cd3a8a7
commit a8a64a2384
8 changed files with 66 additions and 36 deletions
+8 -7
View File
@@ -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
-2
View File
@@ -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
+7 -2
View File
@@ -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"
+38 -11
View File
@@ -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"
+4 -4
View File
@@ -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)
-1
View File
@@ -1 +0,0 @@
create_tenant "first-run"
+8 -8
View File
@@ -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 = [
+1 -1
View File
@@ -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