From 6ea09c0dc0d5d79b2a27587769da40b37929b6f8 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:29:22 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`Tobias`:=20Sprout=20`Tobias`=20Giz?= =?UTF-8?q?mo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/tobias/issues/1 - https://github.com/zinc-collective/convene/issues/709 - For a https://github.com/zinc-collective/tobias/issues/9 to leverage the behavior we described, we need a way to put tobias on the web. https://github.com/zinc-collective/convene/issues/709 are the equivalent of an "App" in the Convene world. - Note: `Gizmo` and `Furniture` are equivalent. We probably should finish https://github.com/zinc-collective/convene/issues/1472 - The migration change makes sure that ahttps://github.com/zinc-collective/tobias/issues/4 is connected to https://github.com/zinc-collective/tobias/issues/1 --- app/furniture/tobias.rb | 13 ++++++++++++- app/furniture/tobias/record.rb | 9 +++++++++ app/furniture/tobias/routes.rb | 9 +++++++++ app/furniture/tobias/trust.rb | 6 +++++- app/furniture/tobias/trusts/show.html.erb | 0 app/furniture/tobias/trusts_controller.rb | 8 ++++++++ app/models/furniture.rb | 1 + db/migrate/20240127063826_create_tobias_payouts.rb | 1 + db/schema.rb | 7 +++++-- spec/tobias/factories/tobias_factory.rb | 5 +++++ spec/tobias/factories/trust_factory.rb | 3 +++ 11 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 app/furniture/tobias/record.rb create mode 100644 app/furniture/tobias/routes.rb create mode 100644 app/furniture/tobias/trusts/show.html.erb create mode 100644 app/furniture/tobias/trusts_controller.rb create mode 100644 spec/tobias/factories/tobias_factory.rb diff --git a/app/furniture/tobias.rb b/app/furniture/tobias.rb index 0dd845ca6..f81576e89 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 singular 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/furniture/tobias/trusts/show.html.erb b/app/furniture/tobias/trusts/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/furniture/tobias/trusts_controller.rb b/app/furniture/tobias/trusts_controller.rb new file mode 100644 index 000000000..1125f8be1 --- /dev/null +++ b/app/furniture/tobias/trusts_controller.rb @@ -0,0 +1,8 @@ +class Tobias + class TrustsController < FurnitureController + + def show + end + + end +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 c52f70b69..4485f4de9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -87,7 +87,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" @@ -291,7 +291,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 @@ -361,8 +361,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| @@ -404,4 +406,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