diff --git a/app/furniture/tobias.rb b/app/furniture/tobias.rb index 0dd845ca6..1fdea6424 100644 --- a/app/furniture/tobias.rb +++ b/app/furniture/tobias.rb @@ -1,2 +1,13 @@ -class Tobias +class Tobias < Furniture + has_many :trusts, inverse_of: :tobias + default_scope { where(furniture_kind: "tobias") } + location(parent: :room) +end + +# TOBIAS is hard to pluralize... Rails presumed TOBIAS was plural, +# So this tells Rails that TOBIAS is the plural form, and that TOBIASes +# is the plural. +ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.plural(/^(tobias)$/i, '\1\2es') + inflect.singular(/^(tobias)es/i, '\1') end diff --git a/app/furniture/tobias/record.rb b/app/furniture/tobias/record.rb new file mode 100644 index 000000000..6763703c1 --- /dev/null +++ b/app/furniture/tobias/record.rb @@ -0,0 +1,9 @@ +class Tobias + class Record < ApplicationRecord + self.abstract_class = true + + def self.model_name + @_model_name ||= ActiveModel::Name.new(self, ::Tobias) + end + end +end diff --git a/app/furniture/tobias/routes.rb b/app/furniture/tobias/routes.rb new file mode 100644 index 000000000..26f1f5e6b --- /dev/null +++ b/app/furniture/tobias/routes.rb @@ -0,0 +1,9 @@ +class Tobias + class Routes + def self.append_routes(router) + router.resources :tobiases, module: "tobias" do + router.resources :trusts + end + end + end +end diff --git a/app/furniture/tobias/trust.rb b/app/furniture/tobias/trust.rb index 357c690fd..852b4ef2c 100644 --- a/app/furniture/tobias/trust.rb +++ b/app/furniture/tobias/trust.rb @@ -1,7 +1,11 @@ class Tobias - class Trust < ApplicationRecord + class Trust < Record self.table_name = "tobias_trusts" + belongs_to :tobias, inverse_of: :trusts + + location(parent: :tobias) + has_many :beneficiaries, inverse_of: :trust, dependent: :destroy has_many :payouts, inverse_of: :trust, dependent: :destroy end diff --git a/app/models/furniture.rb b/app/models/furniture.rb index 6b0f6560b..b7edeb2b8 100644 --- a/app/models/furniture.rb +++ b/app/models/furniture.rb @@ -96,6 +96,7 @@ def self.registry marketplace: ::Marketplace::Marketplace, livestream: ::Livestream, section_navigation: SectionNavigation::SectionNavigation, + tobias: Tobias, embedded_form: EmbeddedForm } end diff --git a/db/migrate/20240127063826_create_tobias_payouts.rb b/db/migrate/20240127063826_create_tobias_payouts.rb index ad6eadffb..bf70cf8a9 100644 --- a/db/migrate/20240127063826_create_tobias_payouts.rb +++ b/db/migrate/20240127063826_create_tobias_payouts.rb @@ -1,6 +1,7 @@ class CreateTobiasPayouts < ActiveRecord::Migration[7.1] def change create_table :tobias_trusts, id: :uuid do |t| + t.references :tobias, type: :uuid, foreign_key: {to_table: :furnitures} t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 9bd70d0f5..575ea565a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -77,7 +77,7 @@ t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 50 t.string "scope" - t.datetime "created_at", precision: nil + t.datetime "created_at" t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id" @@ -265,7 +265,7 @@ t.string "email", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "operator", default: false + t.boolean "operator", default: false, null: false t.index ["email"], name: "index_people_on_email", unique: true end @@ -335,8 +335,10 @@ end create_table "tobias_trusts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "tobias_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["tobias_id"], name: "index_tobias_trusts_on_tobias_id" end create_table "utility_hookups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -376,4 +378,5 @@ add_foreign_key "tobias_payments", "tobias_beneficiaries", column: "beneficiary_id" add_foreign_key "tobias_payments", "tobias_payouts", column: "payout_id" add_foreign_key "tobias_payouts", "tobias_trusts", column: "trust_id" + add_foreign_key "tobias_trusts", "furnitures", column: "tobias_id" end diff --git a/spec/tobias/factories/tobias_factory.rb b/spec/tobias/factories/tobias_factory.rb new file mode 100644 index 000000000..d26bdaa42 --- /dev/null +++ b/spec/tobias/factories/tobias_factory.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :tobias do + room + end +end diff --git a/spec/tobias/factories/trust_factory.rb b/spec/tobias/factories/trust_factory.rb index 7fd94abab..bb7123893 100644 --- a/spec/tobias/factories/trust_factory.rb +++ b/spec/tobias/factories/trust_factory.rb @@ -1,4 +1,7 @@ +require_relative "tobias_factory" + FactoryBot.define do factory :tobias_trust, class: "Tobias::Trust" do + tobias end end