This commit is contained in:
@@ -392,7 +392,7 @@ class PostsController < ApplicationController
|
||||
tag = tags_by_id[tag_id]
|
||||
return nil unless tag
|
||||
|
||||
sections = PostTagSection.where(post_id: post.id, tag_id: tag.id)
|
||||
sections = PostTagSection.where(post_id: post.id, tag_id:)
|
||||
.as_json(only: [:begin_ms, :end_ms])
|
||||
|
||||
if path.include?(tag_id)
|
||||
@@ -419,7 +419,7 @@ class PostsController < ApplicationController
|
||||
|
||||
params[:parent_post_ids].to_s.split.map { |token|
|
||||
id = Integer(token, exception: false)
|
||||
raise ArgumentError, "親投稿 Id. が不正です: #{ token }" if id.nil? || id <= 0
|
||||
raise ArgumentError, "親投稿 Id. が不正です: #{ token }" if !(id) || id <= 0
|
||||
|
||||
id
|
||||
}.uniq
|
||||
|
||||
@@ -102,7 +102,7 @@ class Tag < ApplicationRecord
|
||||
tags = tag_names.map do |name|
|
||||
pf, cat = CATEGORY_PREFIXES.find { |p, _| name.downcase.start_with?(p) } || ['', nil]
|
||||
|
||||
name = TagName.canonicalise(name.sub(/\A#{ pf }/i, '')).first
|
||||
name = name.sub(/\A#{ pf }/i, '')
|
||||
|
||||
sections_by_tag = []
|
||||
while n = name.sub!(/^(\S*?)\[([0-9:.]*?)-([0-9:.]*?)\](\S*?)$/, '\1\4 \2 \3')
|
||||
@@ -116,9 +116,14 @@ class Tag < ApplicationRecord
|
||||
sections_by_tag << [begin_ms, end_ms]
|
||||
end
|
||||
|
||||
name = TagName.canonicalise(name).first
|
||||
|
||||
find_or_create_by_tag_name!(name, category: (cat || :general)).tap do |tag|
|
||||
tag.update!(category: cat) if cat && tag.category != cat
|
||||
sections[tag.id] = sections_by_tag if sections_by_tag.present?
|
||||
next if sections_by_tag.blank?
|
||||
|
||||
sections[tag.id] ||= []
|
||||
sections[tag.id].concat(sections_by_tag)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory :post_tag_section do
|
||||
association :post
|
||||
association :tag
|
||||
begin_ms { 1_000 }
|
||||
end_ms { 2_000 }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :post_tag do
|
||||
association :post
|
||||
association :tag
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory :post do
|
||||
sequence(:url) { |n| "https://example.com/factory-post-#{ n }" }
|
||||
title { 'factory post' }
|
||||
thumbnail_base { nil }
|
||||
uploaded_user { nil }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user