Skip to content

Commit 711eabe

Browse files
committed
Newsモデルとマイグレーション、テストファイルを追加
- title:string、url:string、published_at:datetime の Newsモデルを生成 - url カラムにユニークインデックスを追加し重複登録を防止 - spec/models/news_spec.rb にモデルスペック用ファイルを作成 - spec/factories/news.rb に FactoryBot ファクトリを追加
1 parent 2a9c1f2 commit 711eabe

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

app/models/news.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class News < ApplicationRecord
2+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateNews < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :news do |t|
4+
t.string :title
5+
t.string :url
6+
t.datetime :published_at
7+
8+
t.timestamps
9+
end
10+
11+
add_index :news, :url, unique: true
12+
end
13+
end

db/schema.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2025_05_20_091834) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_06_30_040611) do
1414
# These are extensions that must be enabled in order to support this database
15+
enable_extension "pg_catalog.plpgsql"
1516
enable_extension "pg_stat_statements"
16-
enable_extension "plpgsql"
1717

1818
create_table "dojo_event_services", id: :serial, force: :cascade do |t|
1919
t.integer "dojo_id", null: false
@@ -58,6 +58,15 @@
5858
t.index ["service_name", "event_id"], name: "index_event_histories_on_service_name_and_event_id", unique: true
5959
end
6060

61+
create_table "news", force: :cascade do |t|
62+
t.string "title"
63+
t.string "url"
64+
t.datetime "published_at"
65+
t.datetime "created_at", null: false
66+
t.datetime "updated_at", null: false
67+
t.index ["url"], name: "index_news_on_url", unique: true
68+
end
69+
6170
create_table "podcasts", force: :cascade do |t|
6271
t.string "enclosure_url", null: false
6372
t.string "title", null: false

spec/factories/news.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FactoryBot.define do
2+
factory :news do
3+
title { "MyString" }
4+
url { "MyString" }
5+
published_at { "2025-06-30 13:06:11" }
6+
end
7+
end

spec/models/news_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe News, type: :model do
4+
pending "add some examples to (or delete) #{__FILE__}"
5+
end

0 commit comments

Comments
 (0)