feat: 投稿にニコタグ追加できてしまふバグ修正(#125) (#236)

#125

#125

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #236
This commit was merged in pull request #236.
This commit is contained in:
2026-01-25 00:17:36 +09:00
parent ef3d428a06
commit 0f64ec00f4
3 changed files with 57 additions and 10 deletions
+40 -5
View File
@@ -167,16 +167,34 @@ RSpec.describe 'Posts API', type: :request do
expect(json['tags'][0]).to have_key('name')
end
context "when nico tag already exists in tags" do
before do
Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'),
category: 'nico')
end
it 'return 400' do
sign_in_as(member)
post '/posts', params: {
title: 'new post',
url: 'https://example.com/nico_tag',
tags: 'nico:nico_tag',
thumbnail: dummy_upload }
expect(response).to have_http_status(:bad_request)
end
end
context 'when url is blank' do
it 'returns 422' do
sign_in_as(member)
post '/posts', params: {
title: 'new post',
url: ' ',
tags: 'spec_tag', # 既存タグ名を投げる
thumbnail: dummy_upload
}
title: 'new post',
url: ' ',
tags: 'spec_tag', # 既存タグ名を投げる
thumbnail: dummy_upload }
expect(response).to have_http_status(:unprocessable_entity)
end
@@ -233,6 +251,23 @@ RSpec.describe 'Posts API', type: :request do
names = json['tags'].map { |n| n['name'] }
expect(names).to include('spec_tag_2')
end
context "when nico tag already exists in tags" do
before do
Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'),
category: 'nico')
end
it 'return 400' do
sign_in_as(member)
put "/posts/#{ post_record.id }", params: {
title: 'updated title',
tags: 'nico:nico_tag' }
expect(response).to have_http_status(:bad_request)
end
end
end
describe 'GET /posts/random' do