These will be used by both BlogPost and Micropost
This commit is contained in:
Trevor Vallender 2023-10-19 17:51:32 +01:00
parent 6840302469
commit 3a6de86d48
5 changed files with 36 additions and 1 deletions

5
app/models/tag.rb Normal file
View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
class Tag < ApplicationRecord
validates :name, presence: true
end

View File

@ -0,0 +1,9 @@
class CreateTags < ActiveRecord::Migration[7.1]
def change
create_table :tags do |t|
t.string :name, null: false
t.timestamps
end
end
end

8
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[7.1].define(version: 2023_10_06_070935) do ActiveRecord::Schema[7.1].define(version: 2023_10_19_164620) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -70,6 +70,12 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_06_070935) do
t.index ["user_id"], name: "index_microposts_on_user_id" t.index ["user_id"], name: "index_microposts_on_user_id"
end end
create_table "tags", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "username", null: false t.string "username", null: false
t.string "password_digest", null: false t.string "password_digest", null: false

2
test/fixtures/tags.yml vendored Normal file
View File

@ -0,0 +1,2 @@
sql:
name: sql

13
test/models/tag_test.rb Normal file
View File

@ -0,0 +1,13 @@
require "test_helper"
class TagTest < ActiveSupport::TestCase
setup do
@tag = tags(:sql)
assert @tag.valid?
end
test "must have a name" do
@tag.name = nil
assert_not @tag.valid?
end
end