From 2f23938e813c3ca5e625f3fbaf8964b1a117b73c Mon Sep 17 00:00:00 2001 From: sto Date: Sun, 11 May 2025 19:40:30 +0200 Subject: [PATCH] Add message model --- app/models/message.rb | 24 ++++++++++++++++++ db/migrate/20250511173749_create_messages.rb | 11 +++++++++ db/schema.rb | 12 ++++++++- spec/factories/messages.rb | 26 ++++++++++++++++++++ spec/models/message_spec.rb | 24 ++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 app/models/message.rb create mode 100644 db/migrate/20250511173749_create_messages.rb create mode 100644 spec/factories/messages.rb create mode 100644 spec/models/message_spec.rb diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..42187a1 --- /dev/null +++ b/app/models/message.rb @@ -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 diff --git a/db/migrate/20250511173749_create_messages.rb b/db/migrate/20250511173749_create_messages.rb new file mode 100644 index 0000000..07e3419 --- /dev/null +++ b/db/migrate/20250511173749_create_messages.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b9ef96b..385afd1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| t.string "name", 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" 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| t.string "name" 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 "contestants", "contests" add_foreign_key "contests", "users" + add_foreign_key "messages", "contests" add_foreign_key "puzzles", "contests" add_foreign_key "sessions", "users" end diff --git a/spec/factories/messages.rb b/spec/factories/messages.rb new file mode 100644 index 0000000..d3436db --- /dev/null +++ b/spec/factories/messages.rb @@ -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 diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb new file mode 100644 index 0000000..9157728 --- /dev/null +++ b/spec/models/message_spec.rb @@ -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