This commit is contained in:
2026-04-18 05:39:37 +09:00
parent 9b46e97eaf
commit f4ee3070d6
2 changed files with 15 additions and 6 deletions
@@ -30,7 +30,9 @@ class PostVersionsController < ApplicationController
q = q.where('post_versions.post_id = ?', post_id) if post_id q = q.where('post_versions.post_id = ?', post_id) if post_id
if tag_name if tag_name
escaped = ActiveRecord::Base.sanitize_sql_like(tag_name.name) escaped = ActiveRecord::Base.sanitize_sql_like(tag_name.name)
q = q.where("CONCAT(' ', post_versions.tags, ' ') LIKE ?", "% #{ escaped } %") q = q.where(("CONCAT(' ', post_versions.tags, ' ') LIKE :kw " +
"OR CONCAT(' ', prev.tags, ' ') LIKE :kw"),
kw: "% #{ escaped } %")
end end
count = q.except(:select, :order, :limit, :offset).count count = q.except(:select, :order, :limit, :offset).count
+12 -5
View File
@@ -927,16 +927,23 @@ RSpec.describe 'Posts API', type: :request do
) )
end end
it 'matches tag filter against current tags snapshot only' do it 'filters versions by tag when the tag exists in either current or previous snapshot' do
get '/posts/versions', params: { post: post_record.id, tag: tag.id } get '/posts/versions', params: { post: post_record.id, tag: tag.id }
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(1) expect(json.fetch('count')).to eq(2)
versions = json.fetch('versions') versions = json.fetch('versions')
expect(versions.size).to eq(1) expect(versions.map { |v| v['post_id'] }).to all(eq(post_record.id))
expect(versions[0]['version_no']).to eq(1) expect(versions.map { |v| v['version_no'] }).to eq([2, 1])
expect(versions[0]['tags']).to include(
latest = versions[0]
first = versions[1]
expect(latest['tags']).to include(
{ 'name' => 'spec_tag', 'type' => 'removed' }
)
expect(first['tags']).to include(
{ 'name' => 'spec_tag', 'type' => 'added' } { 'name' => 'spec_tag', 'type' => 'added' }
) )
end end