Add message model
Some checks failed
CI / scan_ruby (push) Failing after 14s
CI / scan_js (push) Successful in 11s
CI / lint (push) Successful in 11s
CI / test (push) Successful in 27s

This commit is contained in:
sto 2025-05-11 19:40:30 +02:00
parent 378c3011ef
commit 2f23938e81
5 changed files with 96 additions and 1 deletions

24
app/models/message.rb Normal file
View File

@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# text :string not null
# time_seconds :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_messages_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
class Message < ApplicationRecord
belongs_to :contest
validates :text, presence: true
end

View File

@ -0,0 +1,11 @@
class CreateMessages < ActiveRecord::Migration[8.0]
def change
create_table :messages do |t|
t.integer :time_seconds, null: false
t.belongs_to :contest, null: false, foreign_key: true
t.string :text, null: false
t.timestamps
end
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[8.0].define(version: 2025_03_27_111835) do ActiveRecord::Schema[8.0].define(version: 2025_05_11_173749) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
@ -86,6 +86,15 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_27_111835) do
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id" t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
end end
create_table "messages", force: :cascade do |t|
t.integer "time_seconds", null: false
t.integer "contest_id", null: false
t.string "text", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["contest_id"], name: "index_messages_on_contest_id"
end
create_table "puzzles", force: :cascade do |t| create_table "puzzles", force: :cascade do |t|
t.string "name" t.string "name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
@ -122,6 +131,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_27_111835) do
add_foreign_key "completions", "puzzles" add_foreign_key "completions", "puzzles"
add_foreign_key "contestants", "contests" add_foreign_key "contestants", "contests"
add_foreign_key "contests", "users" add_foreign_key "contests", "users"
add_foreign_key "messages", "contests"
add_foreign_key "puzzles", "contests" add_foreign_key "puzzles", "contests"
add_foreign_key "sessions", "users" add_foreign_key "sessions", "users"
end end

View File

@ -0,0 +1,26 @@
# == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# text :string not null
# time_seconds :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_messages_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
FactoryBot.define do
factory :message do
time_seconds { 1 }
contest { nil }
text { "MyString" }
end
end

View File

@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# text :string not null
# time_seconds :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_messages_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
require 'rails_helper'
RSpec.describe Message, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end