コミットを比較
1
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
6dc633d23e |
@@ -1,5 +0,0 @@
|
|||||||
class AddIndexToTagsPostCount < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
add_index :tags, :post_count
|
|
||||||
end
|
|
||||||
end
|
|
||||||
生成ファイル
+1
-2
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_11_16_000000) do
|
ActiveRecord::Schema[8.0].define(version: 2026_11_08_020000) do
|
||||||
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -629,7 +629,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_11_16_000000) do
|
|||||||
t.integer "post_count", default: 0, null: false
|
t.integer "post_count", default: 0, null: false
|
||||||
t.integer "version_no", null: false
|
t.integer "version_no", null: false
|
||||||
t.index ["deprecated_at"], name: "index_tags_on_deprecated_at"
|
t.index ["deprecated_at"], name: "index_tags_on_deprecated_at"
|
||||||
t.index ["post_count"], name: "index_tags_on_post_count"
|
|
||||||
t.check_constraint "(`deprecated_at` is null) or (`category` <> _utf8mb4'nico')", name: "chk_tags_deprecated_at_not_nico"
|
t.check_constraint "(`deprecated_at` is null) or (`category` <> _utf8mb4'nico')", name: "chk_tags_deprecated_at_not_nico"
|
||||||
t.check_constraint "`version_no` > 0", name: "chk_tags_version_no_positive"
|
t.check_constraint "`version_no` > 0", name: "chk_tags_version_no_positive"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,17 +2,6 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe Tag, type: :model do
|
RSpec.describe Tag, type: :model do
|
||||||
include WikiRecords
|
include WikiRecords
|
||||||
|
|
||||||
describe 'database indexes' do
|
|
||||||
it 'has a non-unique index on post_count' do
|
|
||||||
indexes = described_class.connection.indexes(described_class.table_name)
|
|
||||||
index = indexes.find { |entry| entry.columns == ['post_count'] }
|
|
||||||
|
|
||||||
expect(index).to be_present
|
|
||||||
expect(index.unique).to be(false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#has_description?' do
|
describe '#has_description?' do
|
||||||
let(:tag) { create(:tag) }
|
let(:tag) { create(:tag) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
import { fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import { textContentOf } from '@/test/text'
|
import { textContentOf } from '@/test/text'
|
||||||
import PostEditForm from '@/components/PostEditForm'
|
import PostEditForm from '@/components/PostEditForm'
|
||||||
@@ -21,14 +21,99 @@ const toastApi = vi.hoisted (() => ({
|
|||||||
vi.mock ('@/lib/posts', () => postsApi)
|
vi.mock ('@/lib/posts', () => postsApi)
|
||||||
vi.mock ('@/lib/api', () => api)
|
vi.mock ('@/lib/api', () => api)
|
||||||
vi.mock ('@/components/ui/use-toast', () => toastApi)
|
vi.mock ('@/components/ui/use-toast', () => toastApi)
|
||||||
vi.mock ('@/lib/dialogues/useDialogue', async importOriginal => ({
|
|
||||||
...await importOriginal<typeof import ('@/lib/dialogues/useDialogue')> (),
|
|
||||||
default: () => ({
|
|
||||||
choice: vi.fn (),
|
|
||||||
}),
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe ('PostEditForm', () => {
|
describe ('PostEditForm', () => {
|
||||||
|
beforeEach (() => {
|
||||||
|
postsApi.updatePost.mockReset ()
|
||||||
|
api.isApiError.mockReset ().mockReturnValue (false)
|
||||||
|
toastApi.toast.mockClear ()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('shows all conflict values before a choice and preserves edits on cancel', async () => {
|
||||||
|
const post = buildPost ({ versionNo: 4, title: 'original title' })
|
||||||
|
const onSave = vi.fn ()
|
||||||
|
api.isApiError.mockReturnValue (true)
|
||||||
|
postsApi.updatePost.mockRejectedValueOnce ({ response: {
|
||||||
|
status: 409,
|
||||||
|
data: { base_version_no: 4, current_version_no: 5, mergeable: false,
|
||||||
|
changes: [
|
||||||
|
{ field: 'title', label: 'server label', base: 'original title',
|
||||||
|
current: 'server title', mine: '<b>my title</b>' },
|
||||||
|
{ field: 'video_ms', base: null, current: 180_500, mine: 0 },
|
||||||
|
{ field: 'original_created_from', base: null,
|
||||||
|
current: '2026-01-01T00:00:00Z', mine: '2026-02-01T00:00:00Z' },
|
||||||
|
{ field: 'original_created_before', base: '2026-01-02T00:00:00Z',
|
||||||
|
current: '2026-01-03T00:00:00Z', mine: null },
|
||||||
|
{ field: 'tag_names', base: ['old-tag'], current: ['tag-a', 'tag-b'],
|
||||||
|
mine: [] },
|
||||||
|
{ field: 'parent_post_ids', base: [2], current: [], mine: [3, 4] }] } } })
|
||||||
|
|
||||||
|
render (<PostEditForm post={post} onSave={onSave}/>)
|
||||||
|
const title = screen.getAllByRole ('textbox')[0]
|
||||||
|
fireEvent.change (title, { target: { value: '<b>my title</b>' } })
|
||||||
|
fireEvent.submit (screen.getByRole ('button', { name: '更新' }).closest ('form')!)
|
||||||
|
|
||||||
|
const dialogue = within (await screen.findByRole ('dialog'))
|
||||||
|
const table = dialogue.getByRole ('table')
|
||||||
|
expect (within (table).getAllByRole ('columnheader').map (cell => cell.textContent))
|
||||||
|
.toEqual (['版 4', '版 5', '編輯'])
|
||||||
|
const rows = within (table).getAllByRole ('row').slice (1)
|
||||||
|
expect (rows.map (row => within (row).getByRole ('rowheader').textContent))
|
||||||
|
.toEqual (['タイトル', '動画時間', 'オリジナルの作成日時 以降',
|
||||||
|
'オリジナルの作成日時 より前', 'タグ', '親投稿'])
|
||||||
|
expect (rows.map (row => within (row).getAllByRole ('cell')
|
||||||
|
.map (cell => cell.textContent))).toEqual ([
|
||||||
|
['original title', 'server title', '<b>my title</b>'],
|
||||||
|
['', '3:00.500', '0:00'],
|
||||||
|
['', '2026-01-01T00:00:00Z', '2026-02-01T00:00:00Z'],
|
||||||
|
['2026-01-02T00:00:00Z', '2026-01-03T00:00:00Z', ''],
|
||||||
|
['old-tag', 'tag-a\ntag-b', ''], ['2', '', '3\n4']])
|
||||||
|
expect (table.querySelector ('b')).toBeNull ()
|
||||||
|
expect (dialogue.queryByText ('server label')).not.toBeInTheDocument ()
|
||||||
|
expect (dialogue.queryByRole ('button', { name: '差分をマージ' }))
|
||||||
|
.not.toBeInTheDocument ()
|
||||||
|
expect (postsApi.updatePost).toHaveBeenCalledTimes (1)
|
||||||
|
expect (onSave).not.toHaveBeenCalled ()
|
||||||
|
|
||||||
|
fireEvent.click (dialogue.getByRole ('button', { name: '取消' }))
|
||||||
|
await waitFor (() => expect (screen.queryByRole ('dialog')).not.toBeInTheDocument ())
|
||||||
|
expect (title).toHaveValue ('<b>my title</b>')
|
||||||
|
await waitFor (() => expect (screen.getByRole ('button', { name: '更新' }))
|
||||||
|
.not.toBeDisabled ())
|
||||||
|
expect (postsApi.updatePost).toHaveBeenCalledTimes (1)
|
||||||
|
expect (onSave).not.toHaveBeenCalled ()
|
||||||
|
})
|
||||||
|
|
||||||
|
it.each ([
|
||||||
|
{ action: '差分をマージ', mergeable: true, options: { merge: true } },
|
||||||
|
{ action: '強制上書き', mergeable: false, options: { force: true } }]) (
|
||||||
|
'keeps the $action flow after displaying conflict values',
|
||||||
|
async ({ action, mergeable, options }) => {
|
||||||
|
const post = buildPost ({ id: 8, versionNo: 4, title: 'original' })
|
||||||
|
const onSave = vi.fn ()
|
||||||
|
api.isApiError.mockReturnValue (true)
|
||||||
|
postsApi.updatePost.mockRejectedValueOnce ({ response: {
|
||||||
|
status: 409,
|
||||||
|
data: { base_version_no: 4, current_version_no: 5, mergeable,
|
||||||
|
changes: [{ field: 'title', base: 'original',
|
||||||
|
current: 'server', mine: 'mine' }] } } })
|
||||||
|
.mockResolvedValueOnce ({ ...post, versionNo: 6, title: 'mine' })
|
||||||
|
|
||||||
|
render (<PostEditForm post={post} onSave={onSave}/>)
|
||||||
|
fireEvent.change (screen.getAllByRole ('textbox')[0], { target: { value: 'mine' } })
|
||||||
|
fireEvent.submit (screen.getByRole ('button', { name: '更新' }).closest ('form')!)
|
||||||
|
|
||||||
|
const dialogue = within (await screen.findByRole ('dialog'))
|
||||||
|
expect (dialogue.getByRole ('table')).toHaveTextContent ('server')
|
||||||
|
fireEvent.click (dialogue.getByRole ('button', { name: action }))
|
||||||
|
await waitFor (() => expect (onSave)
|
||||||
|
.toHaveBeenCalledWith (expect.objectContaining ({ versionNo: 6 })))
|
||||||
|
expect (postsApi.updatePost).toHaveBeenCalledTimes (2)
|
||||||
|
expect (postsApi.updatePost).toHaveBeenLastCalledWith (
|
||||||
|
expect.objectContaining ({ id: 8, title: 'mine' }),
|
||||||
|
{ baseVersionNo: 4, ...options }, 'ja')
|
||||||
|
})
|
||||||
|
|
||||||
it ('submits edited post fields with the current base version', async () => {
|
it ('submits edited post fields with the current base version', async () => {
|
||||||
const onSave = vi.fn ()
|
const onSave = vi.fn ()
|
||||||
const post = buildPost ({
|
const post = buildPost ({
|
||||||
|
|||||||
@@ -23,6 +23,27 @@ type PostFormField =
|
|||||||
'parentPostIds' | 'tags' | 'videoMs'
|
'parentPostIds' | 'tags' | 'videoMs'
|
||||||
| 'originalCreatedAt' | 'originalCreatedFrom' | 'originalCreatedBefore'
|
| 'originalCreatedAt' | 'originalCreatedFrom' | 'originalCreatedBefore'
|
||||||
|
|
||||||
|
type PostConflictValue = string | number | null | (string | number)[]
|
||||||
|
|
||||||
|
type PostConflict = {
|
||||||
|
base_version_no: number
|
||||||
|
current_version_no: number
|
||||||
|
mergeable?: boolean
|
||||||
|
changes?: {
|
||||||
|
field: 'title' | 'video_ms' | 'original_created_from'
|
||||||
|
| 'original_created_before' | 'tag_names' | 'parent_post_ids'
|
||||||
|
base: PostConflictValue
|
||||||
|
current: PostConflictValue
|
||||||
|
mine: PostConflictValue }[] }
|
||||||
|
|
||||||
|
|
||||||
|
const formatConflictValue = (field: string, value: PostConflictValue): string => {
|
||||||
|
if (value == null) return ''
|
||||||
|
if (Array.isArray (value)) return value.join ('\n')
|
||||||
|
return (field === 'video_ms' && typeof value === 'number') ? msToTime (value) : String (value)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const groupedMessages = (...values: (string[] | undefined)[]): string[] =>
|
const groupedMessages = (...values: (string[] | undefined)[]): string[] =>
|
||||||
[...new Set (values.flatMap (value => value ?? []))]
|
[...new Set (values.flatMap (value => value ?? []))]
|
||||||
|
|
||||||
@@ -97,7 +118,7 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
const response = isApiError<{ mergeable?: boolean }> (e) ? e.response : undefined
|
const response = isApiError<PostConflict> (e) ? e.response : undefined
|
||||||
|
|
||||||
if (response?.status !== 409)
|
if (response?.status !== 409)
|
||||||
{
|
{
|
||||||
@@ -113,11 +134,54 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const conflict = response.data
|
||||||
|
const fieldLabels = {
|
||||||
|
title: label ('shared:labels.title'),
|
||||||
|
video_ms: label ('shared:labels.duration'),
|
||||||
|
original_created_from: <>{label ('shared:labels.originalCreatedAt')}
|
||||||
|
{' '}{label ('shared:labels.since')}</>,
|
||||||
|
original_created_before: <>{label ('shared:labels.originalCreatedAt')}
|
||||||
|
{' '}{label ('shared:labels.before')}</>,
|
||||||
|
tag_names: label ('navigation:tags'),
|
||||||
|
parent_post_ids: label ('shared:labels.parentPosts') }
|
||||||
|
|
||||||
const action = await dialogue.choice ({
|
const action = await dialogue.choice ({
|
||||||
title: label ('edit.conflictTitle'),
|
title: label ('edit.conflictTitle'),
|
||||||
description: (
|
description: (
|
||||||
<div>
|
<div>
|
||||||
<p>{label ('edit.conflictDescription')}</p>
|
<p>{label ('edit.conflictDescription')}</p>
|
||||||
|
{(conflict.changes?.length ?? 0) > 0 && (
|
||||||
|
<div className="my-3 max-h-[40dvh] overflow-auto text-left">
|
||||||
|
<table className="w-full table-fixed text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td/>
|
||||||
|
<th scope="col" className="p-1 align-top">
|
||||||
|
{label ('history:version')} {conflict.base_version_no}
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="p-1 align-top">
|
||||||
|
{label ('history:version')} {conflict.current_version_no}
|
||||||
|
</th>
|
||||||
|
<th scope="col" className="p-1 align-top">
|
||||||
|
{label ('shared:actions.edit')}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{conflict.changes?.map (change => (
|
||||||
|
<tr key={change.field}>
|
||||||
|
<th scope="row" className="p-1 align-top break-words">
|
||||||
|
{fieldLabels[change.field]}
|
||||||
|
</th>
|
||||||
|
{(['base', 'current', 'mine'] as const).map (column => (
|
||||||
|
<td key={column}
|
||||||
|
className="p-1 align-top whitespace-pre-wrap break-words">
|
||||||
|
{formatConflictValue (change.field, change[column])}
|
||||||
|
</td>))}
|
||||||
|
</tr>))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>)}
|
||||||
<p>{label ('edit.conflictQuestion')}</p>
|
<p>{label ('edit.conflictQuestion')}</p>
|
||||||
</div>),
|
</div>),
|
||||||
cancelText: label ('shared:actions.cancel'),
|
cancelText: label ('shared:actions.cancel'),
|
||||||
@@ -128,7 +192,6 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
|
|
||||||
if (action === 'merge')
|
if (action === 'merge')
|
||||||
{
|
{
|
||||||
// TODO: 差分 UI
|
|
||||||
await update ({ id: post.id, title, tags, parentPostIds,
|
await update ({ id: post.id, title, tags, parentPostIds,
|
||||||
duration: videoFlg ? duration : null,
|
duration: videoFlg ? duration : null,
|
||||||
originalCreatedFrom, originalCreatedBefore },
|
originalCreatedFrom, originalCreatedBefore },
|
||||||
@@ -218,5 +281,4 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
|||||||
</form>)
|
</form>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default PostEditForm
|
export default PostEditForm
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする