コミットを比較

..

23 コミット

作成者 SHA1 メッセージ 日付
みてるぞ c9b22d346b #306 2026-06-28 06:35:07 +09:00
みてるぞ 283c20b9da #306 2026-06-28 05:59:44 +09:00
みてるぞ ec98c6b756 #306 2026-06-28 03:40:35 +09:00
みてるぞ d721a64e33 #306 2026-06-27 19:06:28 +09:00
みてるぞ 0eb45372c3 #306 2026-06-27 18:52:50 +09:00
みてるぞ 27aa5321a1 #306 2026-06-27 18:43:40 +09:00
みてるぞ 4c0a4f5d9b #306 2026-06-27 18:27:10 +09:00
みてるぞ 41a98ff725 #306 2026-06-27 05:37:58 +09:00
みてるぞ c836369dfc #306 2026-06-27 05:30:23 +09:00
みてるぞ 363146c219 #306 2026-06-27 05:20:25 +09:00
みてるぞ ce28661271 #306 2026-06-26 01:56:01 +09:00
みてるぞ d7b136c198 #306 2026-06-26 01:20:30 +09:00
みてるぞ 4da3f0afba #306 2026-06-26 00:51:40 +09:00
みてるぞ daf9e7e6fa #306 2026-06-26 00:49:18 +09:00
みてるぞ 8304909c8c #306 2026-06-26 00:21:33 +09:00
みてるぞ 377a09ed70 #306 2026-06-25 17:40:34 +09:00
みてるぞ c10ba7a698 #306 2026-06-25 08:11:41 +09:00
みてるぞ fa6c547cc9 #306 2026-06-25 07:44:11 +09:00
みてるぞ dbc654f346 #306 2026-06-25 04:10:43 +09:00
みてるぞ c2102c8f96 #306 2026-06-24 01:26:26 +09:00
みてるぞ 510cbb0d78 #306 2026-06-24 00:38:29 +09:00
みてるぞ a820ce4c3e #306 事故が起きたので,エージェントへの指示を追加 2026-06-23 23:43:01 +09:00
みてるぞ 507ce1680e #306 2026-06-23 22:05:11 +09:00
5個のファイルの変更4行の追加93行の削除
-24
ファイルの表示
@@ -6,7 +6,6 @@ class TagImplication < ApplicationRecord
validates :parent_tag_id, presence: true
validate :parent_tag_mustnt_be_itself
validate :parent_tag_mustnt_create_cycle
private
@@ -15,27 +14,4 @@ class TagImplication < ApplicationRecord
errors.add :parent_tag_id, '親タグは子タグと同一であってはなりません.'
end
end
def parent_tag_mustnt_create_cycle
return if tag_id.blank? || parent_tag_id.blank?
return if errors[:parent_tag_id].present?
seen = { }
stack = [parent_tag_id]
until stack.empty?
current_id = stack.pop
next if seen[current_id]
seen[current_id] = true
if current_id == tag_id
errors.add :parent_tag_id, '親タグに子孫タグを指定すると循環します.'
errors.add :base, 'タグの親子関係が循環します.'
return
end
stack.concat(TagImplication.where(tag_id: current_id).pluck(:parent_tag_id))
end
end
end
-36
ファイルの表示
@@ -1,36 +0,0 @@
require 'rails_helper'
RSpec.describe TagImplication, type: :model do
it 'rejects a parent tag that would create a cycle' do
child = create(:tag, name: 'tag_implication_cycle_child')
parent = create(:tag, name: 'tag_implication_cycle_parent')
described_class.create!(tag: child, parent_tag: parent)
implication = described_class.new(tag: parent, parent_tag: child)
expect(implication).not_to be_valid
expect(implication.errors[:parent_tag_id]).to include(
'親タグに子孫タグを指定すると循環します.'
)
expect(implication.errors[:base]).to be_present
end
it 'terminates even when existing data already contains a cycle' do
child = create(:tag, name: 'tag_implication_existing_cycle_child')
parent = create(:tag, name: 'tag_implication_existing_cycle_parent')
ancestor = create(:tag, name: 'tag_implication_existing_cycle_ancestor')
described_class.create!(tag: parent, parent_tag: ancestor)
described_class.insert_all!(
[
{ tag_id: ancestor.id, parent_tag_id: parent.id,
created_at: Time.current, updated_at: Time.current }
]
)
implication = described_class.new(tag: child, parent_tag: parent)
expect(implication).to be_valid
end
end
+1 -11
ファイルの表示
@@ -54,17 +54,7 @@ RSpec.describe Tag, type: :model do
first = create(:tag, name: 'expand_cycle_first')
second = create(:tag, name: 'expand_cycle_second')
TagImplication.create!(tag: first, parent_tag: second)
now = Time.current
TagImplication.insert_all!(
[
{
tag_id: second.id,
parent_tag_id: first.id,
created_at: now,
updated_at: now
}
]
)
TagImplication.create!(tag: second, parent_tag: first)
expect(described_class.expand_parent_tags([first])).to contain_exactly(first, second)
end
-11
ファイルの表示
@@ -56,17 +56,6 @@ RSpec.describe "TagChildren", type: :request do
expect(response).to have_http_status(:no_content)
end
it 'returns 422 and does not create relation when the new link makes a cycle' do
TagImplication.create!(tag: parent, parent_tag: child)
expect {
do_request
}.not_to change(TagImplication, :count)
expect(response).to have_http_status(:unprocessable_entity)
expect(TagImplication.where(tag: child, parent_tag: parent)).not_to exist
end
end
context "when Tag.find raises (invalid ids)" do
+3 -11
ファイルの表示
@@ -745,17 +745,7 @@ RSpec.describe 'Tags API', type: :request do
)
TagImplication.create!(tag: first, parent_tag: root_material)
TagImplication.create!(tag: second, parent_tag: first)
now = Time.current
TagImplication.insert_all!(
[
{
tag_id: first.id,
parent_tag_id: second.id,
created_at: now,
updated_at: now
}
]
)
TagImplication.create!(tag: first, parent_tag: second)
get '/tags/with-depth', params: { parent: root_material.id }
@@ -1202,6 +1192,8 @@ RSpec.describe 'Tags API', type: :request do
end
it 'parent_tags に指定すると循環する tag は 422 にする' do
pending '#332 で対応予定'
child = Tag.create!(
tag_name: TagName.create!(name: 'put_cycle_child'),
category: :general