Add TextField model

This commit is contained in:
Trevor Vallender 2024-06-14 09:57:13 +01:00
parent c5435ac412
commit de37a7e81f
8 changed files with 57 additions and 1 deletions

View File

@ -9,6 +9,7 @@ class CharacterSheetSection < ApplicationRecord
dependent: :destroy dependent: :destroy
has_many :counters, dependent: :destroy has_many :counters, dependent: :destroy
has_many :stats, dependent: :destroy has_many :stats, dependent: :destroy
has_many :text_fields, dependent: :destroy
validates :name, presence: true, validates :name, presence: true,
length: { maximum: 255 } length: { maximum: 255 }

10
app/models/text_field.rb Normal file
View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class TextField < ApplicationRecord
belongs_to :character_sheet_section
has_rich_text :content
validates :name, presence: true,
length: { maximum: 100 }
end

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class CreateTextFields < ActiveRecord::Migration[7.1]
def change
create_table :text_fields do |t|
t.belongs_to :character_sheet_section, null: false, foreign_key: true
t.string :name, null: false
t.timestamps
end
add_check_constraint :text_fields, "length(name) <= 100", name: "chk_text_field_name_max_length"
end
end

12
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do ActiveRecord::Schema[7.1].define(version: 2024_06_14_084224) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -276,6 +276,15 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
t.check_constraint "length(slug::text) <= 100", name: "chk_table_slug_max_length" t.check_constraint "length(slug::text) <= 100", name: "chk_table_slug_max_length"
end end
create_table "text_fields", force: :cascade do |t|
t.bigint "character_sheet_section_id", null: false
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["character_sheet_section_id"], name: "index_text_fields_on_character_sheet_section_id"
t.check_constraint "length(name::text) <= 100", name: "chk_text_field_name_max_length"
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "username", limit: 20, null: false t.string "username", limit: 20, null: false
t.string "password_digest", limit: 200, null: false t.string "password_digest", limit: 200, null: false
@ -315,4 +324,5 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
add_foreign_key "table_invites", "tables" add_foreign_key "table_invites", "tables"
add_foreign_key "tables", "game_systems" add_foreign_key "tables", "game_systems"
add_foreign_key "tables", "users", column: "owner_id" add_foreign_key "tables", "users", column: "owner_id"
add_foreign_key "text_fields", "character_sheet_sections"
end end

View File

@ -2,3 +2,8 @@ one:
record: trevor (User) record: trevor (User)
name: profile name: profile
body: <p>I am just <strong>so awesome</strong></p> body: <p>I am just <strong>so awesome</strong></p>
two:
record: background (TextField)
name: content
body: <p>Rhino-Man</p>

View File

@ -10,3 +10,7 @@ subsection:
name: Subsection name: Subsection
character: nardren character: nardren
parent_section: stats parent_section: stats
info:
name: Info
character: nardren

3
test/fixtures/text_fields.yml vendored Normal file
View File

@ -0,0 +1,3 @@
background:
character_sheet_section: info
name: Background

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
require "test_helper"
class TextFieldTest < ActiveSupport::TestCase
test "name must exist" do
assert_must_exist(text_fields(:background), :name)
end
end