|
|
|
@@ -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 |
|
|
|
|