Add counters
This commit is contained in:
parent
1c2f8a5576
commit
05ffcf0456
|
@ -7,6 +7,7 @@ class CharacterSheetSection < ApplicationRecord
|
|||
has_many :character_sheet_subsections, class_name: "CharacterSheetSection",
|
||||
foreign_key: :parent_section_id,
|
||||
dependent: :destroy
|
||||
has_many :counters, dependent: :destroy
|
||||
has_many :stats, dependent: :destroy
|
||||
|
||||
validates :name, presence: true,
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Counter < ApplicationRecord
|
||||
include Sluggable
|
||||
|
||||
belongs_to :character_sheet_section
|
||||
|
||||
validates :name, presence: true,
|
||||
length: { maximum: 100 },
|
||||
uniqueness: { scope: :character_sheet_section_id }
|
||||
validates :value, presence: true,
|
||||
numericality: true
|
||||
before_validation :set_slug
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateCounters < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :counters do |t|
|
||||
t.string :name, null: false
|
||||
t.string :slug, null: false
|
||||
t.integer :value, null: false, default: 0
|
||||
t.belongs_to :character_sheet_section, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_check_constraint :counters, "length(name) <= 100", name: "chk_counter_name_max_length"
|
||||
add_check_constraint :counters, "length(slug) <= 100", name: "chk_counter_slug_max_length"
|
||||
|
||||
add_index :counters, :slug, unique: true
|
||||
add_index :counters, [ :name, :character_sheet_section_id ], unique: true
|
||||
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_07_091417) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_12_145451) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -76,6 +76,20 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_07_091417) do
|
|||
t.check_constraint "length(name::text) <= 200", name: "chk_character_name_max_length"
|
||||
end
|
||||
|
||||
create_table "counters", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "slug", null: false
|
||||
t.integer "value", default: 0, null: false
|
||||
t.bigint "character_sheet_section_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["character_sheet_section_id"], name: "index_counters_on_character_sheet_section_id"
|
||||
t.index ["name", "character_sheet_section_id"], name: "index_counters_on_name_and_character_sheet_section_id", unique: true
|
||||
t.index ["slug"], name: "index_counters_on_slug", unique: true
|
||||
t.check_constraint "length(name::text) <= 100", name: "chk_counter_name_max_length"
|
||||
t.check_constraint "length(slug::text) <= 100", name: "chk_counter_slug_max_length"
|
||||
end
|
||||
|
||||
create_table "game_systems", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -213,7 +227,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_07_091417) do
|
|||
t.string "name", null: false
|
||||
t.string "slug", null: false
|
||||
t.bigint "character_sheet_section_id", null: false
|
||||
t.decimal "value", default: "0.0", null: false
|
||||
t.integer "value", default: 0, null: false
|
||||
t.string "roll_command"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
@ -276,6 +290,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_07_091417) do
|
|||
add_foreign_key "characters", "game_systems"
|
||||
add_foreign_key "characters", "tables"
|
||||
add_foreign_key "characters", "users"
|
||||
add_foreign_key "counters", "character_sheet_sections"
|
||||
add_foreign_key "players", "tables"
|
||||
add_foreign_key "players", "users"
|
||||
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
||||
|
|
|
@ -2,6 +2,10 @@ stats:
|
|||
name: Stats
|
||||
character: nardren
|
||||
|
||||
counters:
|
||||
name: Status
|
||||
character: nardren
|
||||
|
||||
subsection:
|
||||
name: Subsection
|
||||
character: nardren
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
hp:
|
||||
name: HP
|
||||
value: 10
|
||||
slug: hp
|
||||
character_sheet_section: counters
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class CounterTest < ActiveSupport::TestCase
|
||||
test "name must exist" do
|
||||
assert_must_exist(counters(:hp), :name)
|
||||
end
|
||||
|
||||
test "value must exist" do
|
||||
assert_must_exist(counters(:hp), :value)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue