Add DiceRoll model
This commit is contained in:
parent
c2c733fcec
commit
0658eca783
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DiceRoll < ApplicationRecord
|
||||
belongs_to :rollable, polymorphic: true
|
||||
belongs_to :table
|
||||
|
||||
validates :result, presence: true,
|
||||
numericality: { only_integer: true }
|
||||
end
|
|
@ -4,6 +4,7 @@ class Stat < ApplicationRecord
|
|||
include Sluggable
|
||||
|
||||
belongs_to :character_sheet_section
|
||||
has_many :dice_rolls, as: :rollable, dependent: :destroy
|
||||
|
||||
validates :name, presence: true,
|
||||
length: { maximum: 100 },
|
||||
|
|
|
@ -4,6 +4,7 @@ class Table < ApplicationRecord
|
|||
belongs_to :owner, class_name: "User"
|
||||
belongs_to :game_system
|
||||
has_many :characters, dependent: :nullify
|
||||
has_many :dice_rolls, dependent: :destroy
|
||||
has_many :players, dependent: :destroy
|
||||
has_many :table_invites, dependent: :destroy
|
||||
has_many :users, through: :players
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateDiceRolls < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :dice_rolls do |t|
|
||||
t.references :rollable, polymorphic: true
|
||||
t.belongs_to :table, null: true, foreign_key: true
|
||||
t.integer :result, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
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_12_145451) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_06_13_072942) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -90,6 +90,17 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_12_145451) do
|
|||
t.check_constraint "length(slug::text) <= 100", name: "chk_counter_slug_max_length"
|
||||
end
|
||||
|
||||
create_table "dice_rolls", force: :cascade do |t|
|
||||
t.string "rollable_type"
|
||||
t.bigint "rollable_id"
|
||||
t.bigint "table_id"
|
||||
t.integer "result", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["rollable_type", "rollable_id"], name: "index_dice_rolls_on_rollable"
|
||||
t.index ["table_id"], name: "index_dice_rolls_on_table_id"
|
||||
end
|
||||
|
||||
create_table "game_systems", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -291,6 +302,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_06_12_145451) do
|
|||
add_foreign_key "characters", "tables"
|
||||
add_foreign_key "characters", "users"
|
||||
add_foreign_key "counters", "character_sheet_sections"
|
||||
add_foreign_key "dice_rolls", "tables"
|
||||
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
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
one:
|
||||
rollable: strength (Stat)
|
||||
table: dnd_table
|
||||
result: 14
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class DiceRollTest < ActiveSupport::TestCase
|
||||
test "result must exist" do
|
||||
assert_must_exist dice_rolls(:one), :result
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue