Browse Source

#308

feature/308
みてるぞ 10 hours ago
parent
commit
f4ee3070d6
2 changed files with 15 additions and 6 deletions
  1. +3
    -1
      backend/app/controllers/post_versions_controller.rb
  2. +12
    -5
      backend/spec/requests/posts_spec.rb

+ 3
- 1
backend/app/controllers/post_versions_controller.rb View File

@@ -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
backend/spec/requests/posts_spec.rb 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[0]['version_no']).to eq(1)
expect(versions[0]['tags']).to include(
expect(versions.map { |v| v['post_id'] }).to all(eq(post_record.id))
expect(versions.map { |v| v['version_no'] }).to eq([2, 1])

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


Loading…
Cancel
Save