|
|
|
@@ -30,6 +30,7 @@ RSpec.describe 'Posts API', type: :request do |
|
|
|
let!(:tag) { Tag.create!(tag_name:, category: "general") } |
|
|
|
let!(:tag_name2) { TagName.create!(name: 'unko') } |
|
|
|
let!(:tag2) { Tag.create!(tag_name: tag_name2, category: 'deerjikist') } |
|
|
|
let!(:alias_tag_name) { TagName.create!(name: 'manko', canonical: tag_name) } |
|
|
|
|
|
|
|
let!(:hit_post) do |
|
|
|
Post.create!(uploaded_user: user, title: "hello spec world", |
|
|
|
@@ -86,6 +87,25 @@ RSpec.describe 'Posts API', type: :request do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
it "filters posts by q (hit case by alias)" do |
|
|
|
get "/posts", params: { tags: "manko" } |
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok) |
|
|
|
posts = json.fetch('posts') |
|
|
|
ids = posts.map { |p| p['id'] } |
|
|
|
|
|
|
|
expect(ids).to include(hit_post.id) |
|
|
|
expect(ids).not_to include(miss_post.id) |
|
|
|
expect(json['count']).to be_an(Integer) |
|
|
|
|
|
|
|
posts.each do |p| |
|
|
|
expect(p['tags']).to be_an(Array) |
|
|
|
p['tags'].each do |t| |
|
|
|
expect(t).to include('name', 'category', 'has_wiki') |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
it "returns empty posts when nothing matches" do |
|
|
|
get "/posts", params: { tags: "no_such_keyword_12345" } |
|
|
|
|
|
|
|
@@ -167,6 +187,26 @@ RSpec.describe 'Posts API', type: :request do |
|
|
|
expect(json['tags'][0]).to have_key('name') |
|
|
|
end |
|
|
|
|
|
|
|
it '201 and creates post + tags when member and tags have aliases' do |
|
|
|
sign_in_as(member) |
|
|
|
|
|
|
|
post '/posts', params: { |
|
|
|
title: 'new post', |
|
|
|
url: 'https://example.com/new', |
|
|
|
tags: 'manko', # 既存タグ名を投げる |
|
|
|
thumbnail: dummy_upload |
|
|
|
} |
|
|
|
|
|
|
|
expect(response).to have_http_status(:created) |
|
|
|
expect(json).to include('id', 'title', 'url') |
|
|
|
|
|
|
|
# tags が name を含むこと(API 側の serialization が正しいこと) |
|
|
|
expect(json).to have_key('tags') |
|
|
|
expect(json['tags']).to be_an(Array) |
|
|
|
expect(json['tags'][0]).to have_key('name') |
|
|
|
expect(json['tags'][0]['name']).to eq('spec_tag') |
|
|
|
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'), |
|
|
|
|