コミットを比較
2
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
5303eaa31a | ||
|
|
f39aa04e9a |
@@ -5,7 +5,6 @@ class MaterialVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class MaterialsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class NicoTagsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
post_tag_max_sql =
|
post_tag_max_sql =
|
||||||
PostExternalTag
|
PostExternalTag
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class PostVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class PostsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class TagVersionsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class TagsController < ApplicationController
|
|||||||
|
|
||||||
page = 1 if page < 1
|
page = 1 if page < 1
|
||||||
limit = 1 if limit < 1
|
limit = 1 if limit < 1
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreCommentsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 20 if limit <= 0
|
limit = 20 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
no_gt = params[:no_gt].to_i
|
no_gt = params[:no_gt].to_i
|
||||||
no_gt = 0 if no_gt < 0
|
no_gt = 0 if no_gt < 0
|
||||||
@@ -10,7 +9,6 @@ class TheatreCommentsController < ApplicationController
|
|||||||
comments = TheatreComment
|
comments = TheatreComment
|
||||||
.where(theatre_id: params[:theatre_id])
|
.where(theatre_id: params[:theatre_id])
|
||||||
.where('no > ?', no_gt)
|
.where('no > ?', no_gt)
|
||||||
.includes(:user)
|
|
||||||
.order(no: :desc)
|
.order(no: :desc)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreProgrammesController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 100 if limit <= 0
|
limit = 100 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
position_gt = params[:position_gt].to_i
|
position_gt = params[:position_gt].to_i
|
||||||
position_gt = 0 if position_gt < 0
|
position_gt = 0 if position_gt < 0
|
||||||
@@ -11,7 +10,7 @@ class TheatreProgrammesController < ApplicationController
|
|||||||
.where(theatre_id: params[:theatre_id])
|
.where(theatre_id: params[:theatre_id])
|
||||||
.where('position > ?', position_gt)
|
.where('position > ?', position_gt)
|
||||||
.includes(:post)
|
.includes(:post)
|
||||||
.order(position: :desc)
|
.order(position: :desc).limit(100)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
||||||
render json: programmes.map { |programme|
|
render json: programmes.map { |programme|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ class TheatreSkipEventsController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
limit = params[:limit].to_i
|
limit = params[:limit].to_i
|
||||||
limit = 50 if limit <= 0
|
limit = 50 if limit <= 0
|
||||||
limit = 100 if limit > 100
|
|
||||||
|
|
||||||
events =
|
events =
|
||||||
TheatreSkipEvent
|
TheatreSkipEvent
|
||||||
|
|||||||
@@ -1,174 +0,0 @@
|
|||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'List API limits', type: :request do
|
|
||||||
shared_examples 'a capped list' do |default_count, minimum_count, paginated|
|
|
||||||
def response_rows
|
|
||||||
body = json
|
|
||||||
body.is_a?(Array) ? body : body.fetch(collection_key)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'caps oversized limits at 100 and preserves the 100 boundary' do
|
|
||||||
get path, params: { locale: 'ja', limit: 100 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(100)
|
|
||||||
boundary_rows = response_rows
|
|
||||||
|
|
||||||
[101, 10_000].each do |limit|
|
|
||||||
get path, params: { locale: 'ja', limit: }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows).to eq(boundary_rows)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'preserves the default, nonpositive and small positive limits' do
|
|
||||||
get path, params: { locale: 'ja' }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(default_count)
|
|
||||||
|
|
||||||
[0, -1].each do |limit|
|
|
||||||
get path, params: { locale: 'ja', limit: }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(minimum_count)
|
|
||||||
end
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if paginated
|
|
||||||
it 'uses the capped limit for page offsets and preserves total count' do
|
|
||||||
get path, params: { locale: 'ja', limit: 100 }
|
|
||||||
first_page = response_rows
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(json.fetch('count')).to eq(101)
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 100, page: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows.size).to eq(1)
|
|
||||||
second_page = response_rows
|
|
||||||
expect(first_page & second_page).to be_empty
|
|
||||||
|
|
||||||
get path, params: { locale: 'ja', limit: 101, page: 2 }
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
expect(response_rows).to eq(second_page)
|
|
||||||
expect(json.fetch('count')).to eq(101)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'posts' do
|
|
||||||
let(:path) { '/posts' }
|
|
||||||
let(:collection_key) { 'posts' }
|
|
||||||
before { create_list(:post, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'tags' do
|
|
||||||
let(:path) { '/tags' }
|
|
||||||
let(:collection_key) { 'tags' }
|
|
||||||
before { create_list(:tag, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'nico tags' do
|
|
||||||
let(:path) { '/tags/nico' }
|
|
||||||
let(:collection_key) { 'tags' }
|
|
||||||
before { create_list(:external_tag, 101) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'materials' do
|
|
||||||
let(:path) { '/materials' }
|
|
||||||
let(:collection_key) { 'materials' }
|
|
||||||
before do
|
|
||||||
101.times { |index| Material.create!(url: "https://example.com/material-#{ index }") }
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'post versions' do
|
|
||||||
let(:path) { '/posts/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:post) { create(:post) }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
PostVersion.create!(post:, version_no: index + 1, event_type: 'update',
|
|
||||||
url: post.url, tags: '', tags_json: [], parent_post_ids: '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'tag versions' do
|
|
||||||
let(:path) { '/tags/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:tag) { create(:tag) }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TagVersion.create!(tag:, version_no: index + 1, event_type: 'update',
|
|
||||||
name: 'limit tag', category: 'general', aliases: '',
|
|
||||||
parent_tag_ids: '', names: {
|
|
||||||
ja: { name: 'limit tag', script_code: 'Jpan',
|
|
||||||
auto_generated: false, aliases: [] } })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'material versions' do
|
|
||||||
let(:path) { '/materials/versions' }
|
|
||||||
let(:collection_key) { 'versions' }
|
|
||||||
let(:material) { Material.create!(url: 'https://example.com/material') }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
MaterialVersion.create!(material:, version_no: index + 1,
|
|
||||||
event_type: 'update', url: material.url)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 1, true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'theatre lists' do
|
|
||||||
let(:theatre) { create(:theatre) }
|
|
||||||
let(:post) { create(:post) }
|
|
||||||
|
|
||||||
context 'comments' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/comments" }
|
|
||||||
before { create_list(:theatre_comment, 101, theatre:, user: theatre.created_by_user) }
|
|
||||||
|
|
||||||
include_examples 'a capped list', 20, 20, false
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'programmes' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/programmes" }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TheatreProgramme.create!(theatre:, post:, position: index + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 100, 100, false
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'skip events' do
|
|
||||||
let(:path) { "/theatres/#{ theatre.id }/skip_events" }
|
|
||||||
before do
|
|
||||||
101.times do |index|
|
|
||||||
TheatreSkipEvent.create!(theatre:, post:,
|
|
||||||
skipped_by_user: theatre.created_by_user,
|
|
||||||
created_at: Time.utc(2026, 1, 1) + index.seconds)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'a capped list', 50, 50, false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,9 +1,25 @@
|
|||||||
|
import { screen } from '@testing-library/react'
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
import DraggableDroppableTagRow from '@/components/DraggableDroppableTagRow'
|
import DraggableDroppableTagRow from '@/components/DraggableDroppableTagRow'
|
||||||
import { buildTag } from '@/test/factories'
|
import { buildTag } from '@/test/factories'
|
||||||
import { renderWithProviders } from '@/test/render'
|
import { renderWithProviders } from '@/test/render'
|
||||||
|
|
||||||
|
import type { CSSProperties, ReactNode } from 'react'
|
||||||
|
|
||||||
|
vi.mock ('framer-motion', async importOriginal => {
|
||||||
|
const original = await importOriginal<typeof import ('framer-motion')> ()
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
motion: {
|
||||||
|
...original.motion,
|
||||||
|
div: ({ children, style, layoutId }: {
|
||||||
|
children?: ReactNode
|
||||||
|
style?: CSSProperties
|
||||||
|
layoutId?: string }) => (
|
||||||
|
<div style={style} data-layout-id={layoutId}>{children}</div>) } }
|
||||||
|
})
|
||||||
|
|
||||||
const dndKit = vi.hoisted (() => ({
|
const dndKit = vi.hoisted (() => ({
|
||||||
useDraggable: vi.fn (),
|
useDraggable: vi.fn (),
|
||||||
useDroppable: vi.fn (),
|
useDroppable: vi.fn (),
|
||||||
@@ -97,4 +113,32 @@ describe ('DraggableDroppableTagRow', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it.each ([false, true]) (
|
||||||
|
'separates same-id internal and external animation identities (sp=%s)',
|
||||||
|
sp => {
|
||||||
|
const internal = buildTag ({ id: 7, name: 'internal_collision' })
|
||||||
|
const external = buildTag ({
|
||||||
|
id: 7, name: 'nico:external_collision', category: 'nico' })
|
||||||
|
|
||||||
|
renderWithProviders (
|
||||||
|
<>
|
||||||
|
{[internal, external].map (item => (
|
||||||
|
<DraggableDroppableTagRow
|
||||||
|
key={item.category}
|
||||||
|
tag={item}
|
||||||
|
nestLevel={0}
|
||||||
|
pathKey={`cat-${ item.category }-7`}
|
||||||
|
suppressClickRef={{ current: false }}
|
||||||
|
sp={sp}/>))}
|
||||||
|
</>)
|
||||||
|
|
||||||
|
const prefix = sp ? 'tag-sp-' : 'tag-'
|
||||||
|
for (const item of [internal, external])
|
||||||
|
{
|
||||||
|
expect (screen.getByRole ('link', { name: item.name })
|
||||||
|
.closest ('[data-layout-id]')).toHaveAttribute (
|
||||||
|
'data-layout-id', `${ prefix }${ item.category }-7`)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ const DraggableDroppableTagRow: FC<Props> = ({
|
|||||||
transition={{ layout: layoutTransition }}
|
transition={{ layout: layoutTransition }}
|
||||||
layoutId={animationMode === 'off'
|
layoutId={animationMode === 'off'
|
||||||
? undefined
|
? undefined
|
||||||
: `tag-${ sp ? 'sp-' : '' }${ tag.id }`}>
|
: `tag-${ sp ? 'sp-' : '' }${ tag.category }-${ tag.id }`}>
|
||||||
<TagLink tag={tag} nestLevel={nestLevel}/>
|
<TagLink tag={tag} nestLevel={nestLevel}/>
|
||||||
</motion.div>)}
|
</motion.div>)}
|
||||||
</div>)
|
</div>)
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { screen } from '@testing-library/react'
|
||||||
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
|
import TagSidebar from '@/components/TagSidebar'
|
||||||
|
import { buildPost, buildTag } from '@/test/factories'
|
||||||
|
import { renderWithProviders } from '@/test/render'
|
||||||
|
|
||||||
|
import type { ReactNode } from 'react'
|
||||||
|
|
||||||
|
vi.mock ('@/components/TagSearch', () => ({ default: () => null }))
|
||||||
|
vi.mock ('@/components/layout/SidebarComponent', () => ({
|
||||||
|
default: ({ children }: { children: ReactNode }) => <>{children}</> }))
|
||||||
|
|
||||||
|
vi.mock ('framer-motion', async importOriginal => {
|
||||||
|
const original = await importOriginal<typeof import ('framer-motion')> ()
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
motion: {
|
||||||
|
...original.motion,
|
||||||
|
div: ({ children, layoutId }: {
|
||||||
|
children?: ReactNode
|
||||||
|
layoutId?: string }) => (
|
||||||
|
<div data-layout-id={layoutId}>{children}</div>) } }
|
||||||
|
})
|
||||||
|
|
||||||
|
describe ('TagSidebar', () => {
|
||||||
|
it ('keeps same-id internal and external tags with distinct identities', () => {
|
||||||
|
const errors = vi.spyOn (console, 'error').mockImplementation (() => {})
|
||||||
|
const internal = buildTag ({ id: 7, name: 'internal_collision' })
|
||||||
|
const external = buildTag ({
|
||||||
|
id: 7, name: 'nico:external_collision', category: 'nico' })
|
||||||
|
|
||||||
|
renderWithProviders (
|
||||||
|
<TagSidebar posts={[buildPost ({ tags: [internal, external] })]}/>)
|
||||||
|
|
||||||
|
for (const item of [internal, external])
|
||||||
|
{
|
||||||
|
const link = screen.getByRole ('link', { name: item.name })
|
||||||
|
expect (link).toBeInTheDocument ()
|
||||||
|
expect (link.closest ('[data-layout-id]')).toHaveAttribute (
|
||||||
|
'data-layout-id', `tag-${ item.category }-7`)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect (errors.mock.calls.filter (args =>
|
||||||
|
args.some (value => String (value).includes ('same key')))).toEqual ([])
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -84,7 +84,8 @@ const TagSidebar: FC<Props> = ({ posts, onClick }) => {
|
|||||||
<ul>
|
<ul>
|
||||||
{CATEGORIES.flatMap (cat => cat in tags ? (
|
{CATEGORIES.flatMap (cat => cat in tags ? (
|
||||||
tags[cat].map (tag => (
|
tags[cat].map (tag => (
|
||||||
<li key={tag.id} className="mb-1 min-w-0 max-w-full overflow-hidden">
|
<li key={`${ cat }-${ tag.id }`}
|
||||||
|
className="mb-1 min-w-0 max-w-full overflow-hidden">
|
||||||
{animationsOff
|
{animationsOff
|
||||||
? (
|
? (
|
||||||
<div className="flex min-w-0 max-w-full items-baseline overflow-hidden">
|
<div className="flex min-w-0 max-w-full items-baseline overflow-hidden">
|
||||||
@@ -94,7 +95,7 @@ const TagSidebar: FC<Props> = ({ posts, onClick }) => {
|
|||||||
<motion.div
|
<motion.div
|
||||||
className="flex min-w-0 max-w-full items-baseline overflow-hidden"
|
className="flex min-w-0 max-w-full items-baseline overflow-hidden"
|
||||||
transition={{ layout: layoutTransition }}
|
transition={{ layout: layoutTransition }}
|
||||||
layoutId={`tag-${ tag.id }`}>
|
layoutId={`tag-${ cat }-${ tag.id }`}>
|
||||||
<TagLink tag={tag} onClick={onClick}/>
|
<TagLink tag={tag} onClick={onClick}/>
|
||||||
</motion.div>)}
|
</motion.div>)}
|
||||||
</li>))) : [])}
|
</li>))) : [])}
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする