-
-
Notifications
You must be signed in to change notification settings - Fork 109
News specの強化(追加ケースの実装) #1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
News specの強化(追加ケースの実装) #1719
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e29ea1
test: Newsモデルのバリデーション・スコープのテストを追加
nacchan99 b0f4365
test: Newsモデルスペックの説明を日本語で統一
nacchan99 052cfe2
test: news RakeタスクのRSpecを追加 & fetch/importタスクを修正
nacchan99 b35ad64
test: news:fetchタスクのエラーハンドリング用RSpecを追加
claude[bot] 9951bae
test: news:fetch タスクのエラーハンドリングテストを追加
nacchan99 1850e1f
方針変更により不要となったnewsタスク関連のテストを削除
nacchan99 d4e0150
chore: 今回のPRと関係ない変更を削除(#1724の重複分)
nacchan99 7b0b652
chore: 不要なファクトリーテストを削除
nacchan99 76202d8
test: titleバリデーションの有効ケースを追加
nacchan99 2708091
test: published_atバリデーションの有効ケースを追加
nacchan99 3cb6d0d
refactor: urlバリデーションテストをcontextで整理し、説明文を改善
nacchan99 2305a9d
style: title・published_atセクションのインデントを調整
nacchan99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,79 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe News, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
describe 'バリデーション' do | ||
let(:news) { build(:news) } | ||
|
||
describe 'title' do | ||
it 'タイトルが空の場合は無効になる' do | ||
news.title = nil | ||
expect(news).not_to be_valid | ||
expect(news.errors[:title]).not_to be_empty | ||
end | ||
|
||
it 'タイトルが正しく設定されている場合は有効になる' do | ||
news.title = '有効なタイトル' | ||
expect(news).to be_valid | ||
end | ||
end | ||
|
||
describe 'url' do | ||
context '無効な場合' do | ||
it 'URL が空の場合は無効になる' do | ||
news.url = nil | ||
expect(news).not_to be_valid | ||
expect(news.errors[:url]).not_to be_empty | ||
end | ||
|
||
it 'URL が重複している場合は無効になる' do | ||
create(:news, url: 'https://example.com/test') | ||
duplicate_news = build(:news, url: 'https://example.com/test') | ||
expect(duplicate_news).not_to be_valid | ||
expect(duplicate_news.errors[:url]).not_to be_empty | ||
end | ||
|
||
it 'URL形式でない場合は無効になる' do | ||
news.url = 'invalid-url' | ||
expect(news).not_to be_valid | ||
expect(news.errors[:url]).not_to be_empty | ||
end | ||
end | ||
|
||
context '有効な場合' do | ||
it 'HTTPSを許可する' do | ||
news.url = 'https://example.com' | ||
expect(news).to be_valid | ||
end | ||
|
||
it 'HTTPを許可する' do | ||
news.url = 'http://example.com' | ||
expect(news).to be_valid | ||
end | ||
end | ||
end | ||
|
||
describe 'published_at' do | ||
it '公開日時が空の場合は無効になる' do | ||
news.published_at = nil | ||
expect(news).not_to be_valid | ||
expect(news.errors[:published_at]).not_to be_empty | ||
end | ||
|
||
it '公開日時が正しく設定されている場合は有効になる' do | ||
news.published_at = Time.current | ||
expect(news).to be_valid | ||
end | ||
end | ||
end | ||
|
||
describe 'スコープ' do | ||
describe '.recent' do | ||
it '公開日時の降順で並び替える' do | ||
old_news = create(:news, published_at: 2.days.ago) | ||
new_news = create(:news, published_at: 1.day.ago) | ||
|
||
expect(News.recent).to eq([new_news, old_news]) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.