Merge branch 'main' into filter-input-tweaks
This commit is contained in:
+3
-11
@@ -4,17 +4,9 @@ class Account < ApplicationRecord
|
||||
has_many_attached :uploads
|
||||
|
||||
class << self
|
||||
def create_with_admin_user(tenant_id:, account_name:, owner_name:, owner_email:)
|
||||
account = create!(tenant_id:, name: account_name)
|
||||
|
||||
User.create!(
|
||||
name: owner_name,
|
||||
email_address: owner_email,
|
||||
role: "admin",
|
||||
password: SecureRandom.hex(16)
|
||||
)
|
||||
|
||||
account
|
||||
def create_with_admin_user(account:, owner:)
|
||||
User.create!(**owner.reverse_merge(role: "admin", password: SecureRandom.hex(16)))
|
||||
create!(**account)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ bin/rails runner - <<EOF
|
||||
puts "Login with david@37signals.com / secret123456 to:"
|
||||
ApplicationRecord.with_each_tenant do |tenant|
|
||||
next unless tenant =~ /\A\d+\z/
|
||||
next unless Account.count > 0
|
||||
puts " - #{Account.sole.name}: http://fizzy.localhost:3006#{Account.sole.slug}"
|
||||
end
|
||||
EOF
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameAccountsTenantIdToExternalAccountId < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
rename_column :accounts, :tenant_id, :external_account_id
|
||||
end
|
||||
end
|
||||
Generated
+3
-3
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.1].define(version: 2025_10_01_181713) do
|
||||
ActiveRecord::Schema[8.1].define(version: 2025_10_03_205559) do
|
||||
create_table "accesses", force: :cascade do |t|
|
||||
t.datetime "accessed_at"
|
||||
t.integer "collection_id", null: false
|
||||
@@ -26,11 +26,11 @@ ActiveRecord::Schema[8.1].define(version: 2025_10_01_181713) do
|
||||
|
||||
create_table "accounts", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.integer "external_account_id"
|
||||
t.string "join_code"
|
||||
t.string "name", null: false
|
||||
t.integer "tenant_id"
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["tenant_id"], name: "index_accounts_on_tenant_id", unique: true
|
||||
t.index ["external_account_id"], name: "index_accounts_on_external_account_id", unique: true
|
||||
end
|
||||
|
||||
create_table "action_text_rich_texts", force: :cascade do |t|
|
||||
|
||||
+13
-13
@@ -102,6 +102,16 @@ columns:
|
||||
comment:
|
||||
accounts:
|
||||
- *5
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: external_account_id
|
||||
cast_type: *3
|
||||
sql_type_metadata: *4
|
||||
'null': true
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- *6
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
@@ -123,16 +133,6 @@ columns:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: tenant_id
|
||||
cast_type: *3
|
||||
sql_type_metadata: *4
|
||||
'null': true
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- *9
|
||||
action_text_rich_texts:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
@@ -1666,10 +1666,10 @@ indexes:
|
||||
accounts:
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
|
||||
table: accounts
|
||||
name: index_accounts_on_tenant_id
|
||||
name: index_accounts_on_external_account_id
|
||||
unique: true
|
||||
columns:
|
||||
- tenant_id
|
||||
- external_account_id
|
||||
lengths: {}
|
||||
orders: {}
|
||||
opclasses: {}
|
||||
@@ -3222,4 +3222,4 @@ indexes:
|
||||
comment:
|
||||
valid: true
|
||||
workflows: []
|
||||
version: 20251001181713
|
||||
version: 20251003205559
|
||||
|
||||
+8
-4
@@ -20,10 +20,14 @@ def create_tenant(signal_account_name, bare: false)
|
||||
ApplicationRecord.destroy_tenant tenant_id
|
||||
ApplicationRecord.create_tenant(tenant_id) do
|
||||
account = Account.create_with_admin_user(
|
||||
tenant_id: tenant_id,
|
||||
account_name: signal_account_name,
|
||||
owner_name: "David Heinemeier Hansson",
|
||||
owner_email: "david@37signals.com",
|
||||
account: {
|
||||
external_account_id: tenant_id,
|
||||
name: signal_account_name
|
||||
},
|
||||
owner: {
|
||||
name: "David Heinemeier Hansson",
|
||||
email_address: "david@37signals.com"
|
||||
}
|
||||
)
|
||||
account.setup_basic_template
|
||||
end
|
||||
|
||||
Vendored
-3
@@ -1,6 +1,3 @@
|
||||
37s:
|
||||
name: 37signals
|
||||
join_code: "ejpP-THlQ-Cc2f"
|
||||
<% if Account.reflect_on_association :external_account %>
|
||||
tenant_id: <%= ActiveRecord::FixtureSet.identify :'37s_fizzy' %>
|
||||
<% end %>
|
||||
|
||||
@@ -9,15 +9,19 @@ class AccountTest < ActiveSupport::TestCase
|
||||
test ".create_with_admin_user creates a new local account" do
|
||||
ApplicationRecord.create_tenant("account-create-with-dependents") do
|
||||
account = Account.create_with_admin_user(
|
||||
tenant_id: ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"),
|
||||
account_name: "Account Create With Admin",
|
||||
owner_name: "David",
|
||||
owner_email: "david@37signals.com")
|
||||
|
||||
account: {
|
||||
external_account_id: ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"),
|
||||
name: "Account Create With Admin"
|
||||
},
|
||||
owner: {
|
||||
name: "David",
|
||||
email_address: "david@37signals.com"
|
||||
}
|
||||
)
|
||||
assert_not_nil account
|
||||
assert account.persisted?
|
||||
assert_equal 1, Account.count
|
||||
assert_equal ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"), account.tenant_id
|
||||
assert_equal ActiveRecord::FixtureSet.identify("account-create-with-admin-user-test"), account.external_account_id
|
||||
assert_equal "Account Create With Admin", account.name
|
||||
|
||||
assert_equal 1, User.count
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../config/environment"
|
||||
|
||||
Rails.application.config.active_record_tenanted.default_tenant = ActiveRecord::FixtureSet.identify :'37s_fizzy'
|
||||
# there's no fixture for this, we're just generating a stable integer
|
||||
Rails.application.config.active_record_tenanted.default_tenant = ActiveRecord::FixtureSet.identify "37s_fizzy"
|
||||
|
||||
require "rails/test_help"
|
||||
require "webmock/minitest"
|
||||
|
||||
Reference in New Issue
Block a user