Add tags
These will be used by both BlogPost and Micropost
This commit is contained in:
parent
6840302469
commit
3a6de86d48
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Tag < ApplicationRecord
|
||||
validates :name, presence: true
|
||||
end
|
|
@ -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
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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
|
||||
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"
|
||||
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|
|
||||
t.string "username", null: false
|
||||
t.string "password_digest", null: false
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
sql:
|
||||
name: sql
|
|
@ -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
|
Loading…
Reference in New Issue