diff --git a/app/models/tag.rb b/app/models/tag.rb new file mode 100644 index 0000000..b44e9fa --- /dev/null +++ b/app/models/tag.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Tag < ApplicationRecord + validates :name, presence: true +end diff --git a/db/migrate/20231019164620_create_tags.rb b/db/migrate/20231019164620_create_tags.rb new file mode 100644 index 0000000..407e4b2 --- /dev/null +++ b/db/migrate/20231019164620_create_tags.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 3a4ee54..7149b7b 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[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 diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml new file mode 100644 index 0000000..a1057bb --- /dev/null +++ b/test/fixtures/tags.yml @@ -0,0 +1,2 @@ +sql: + name: sql diff --git a/test/models/tag_test.rb b/test/models/tag_test.rb new file mode 100644 index 0000000..4812fb1 --- /dev/null +++ b/test/models/tag_test.rb @@ -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