Add message model
This commit is contained in:
		
							
								
								
									
										24
									
								
								app/models/message.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								app/models/message.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
							
								
								
									
										11
									
								
								db/migrate/20250511173749_create_messages.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								db/migrate/20250511173749_create_messages.rb
									
									
									
									
									
										Normal 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
									
									
									
								
							
							
						
						
									
										12
									
								
								db/schema.rb
									
									
									
										generated
									
									
									
								
							@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								spec/factories/messages.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								spec/factories/messages.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
							
								
								
									
										24
									
								
								spec/models/message_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								spec/models/message_spec.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user