Add CharacterSheetSection model
This commit is contained in:
parent
9fe186a08d
commit
701d69fcc9
|
@ -4,6 +4,7 @@ class Character < ApplicationRecord
|
|||
belongs_to :table, optional: true
|
||||
belongs_to :game_system
|
||||
belongs_to :user
|
||||
has_many :character_sheet_sections, dependent: :destroy
|
||||
|
||||
validates :name, presence: true,
|
||||
length: { maximum: 200 }
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CharacterSheetSection < ApplicationRecord
|
||||
belongs_to :character
|
||||
belongs_to :parent_section, optional: true
|
||||
has_many :character_sheet_subsections, class_name: "CharacterSheetSection"
|
||||
|
||||
validates :name, presence: true,
|
||||
length: { maximum: 255 }
|
||||
|
||||
scope :top_level, -> { where.missing(:parent_section) }
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateCharacterSheetSections < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :character_sheet_sections do |t|
|
||||
t.string :name, null: false
|
||||
t.belongs_to :character, null: false, foreign_key: true
|
||||
t.references :parent_section, null: true, foreign_key: { to_table: :character_sheet_sections }
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_check_constraint :character_sheet_sections, "length(name) <= 255", name: "chk_character_sheet_section_name_max_length"
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_05_143732) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_05_175553) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -52,6 +52,17 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_05_143732) do
|
|||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table "character_sheet_sections", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.bigint "character_id", null: false
|
||||
t.bigint "parent_section_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["character_id"], name: "index_character_sheet_sections_on_character_id"
|
||||
t.index ["parent_section_id"], name: "index_character_sheet_sections_on_parent_section_id"
|
||||
t.check_constraint "length(name::text) <= 255", name: "chk_character_sheet_section_name_max_length"
|
||||
end
|
||||
|
||||
create_table "characters", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.bigint "table_id"
|
||||
|
@ -245,6 +256,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_05_143732) do
|
|||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "character_sheet_sections", "character_sheet_sections", column: "parent_section_id"
|
||||
add_foreign_key "character_sheet_sections", "characters"
|
||||
add_foreign_key "characters", "game_systems"
|
||||
add_foreign_key "characters", "tables"
|
||||
add_foreign_key "characters", "users"
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
stats:
|
||||
name: Stats
|
||||
character: nardren
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class CharacterSheetSectionTest < ActiveSupport::TestCase
|
||||
test "name must exist" do
|
||||
assert_must_exist(character_sheet_sections(:stats), "name")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue