このコミットが含まれているのは:
@@ -113,6 +113,68 @@ RSpec.describe 'Materials API', type: :request do
|
||||
expect(response_materials.size).to eq(1)
|
||||
expect(response_materials.first['id']).to eq(material_b.id)
|
||||
end
|
||||
|
||||
it 'filters by descendant tags and returns stable parent tag groups' do
|
||||
root =
|
||||
Tag.create!(tag_name: TagName.create!(name: 'material_scope_root'),
|
||||
category: :material)
|
||||
child_b =
|
||||
Tag.create!(tag_name: TagName.create!(name: 'material_scope_b'),
|
||||
category: :material)
|
||||
child_a =
|
||||
Tag.create!(tag_name: TagName.create!(name: 'material_scope_a'),
|
||||
category: :material)
|
||||
deprecated =
|
||||
Tag.create!(tag_name: TagName.create!(name: 'material_scope_old'),
|
||||
category: :material,
|
||||
deprecated_at: Time.current)
|
||||
grandchild =
|
||||
Tag.create!(tag_name: TagName.create!(name: 'material_scope_grandchild'),
|
||||
category: :material)
|
||||
root_material =
|
||||
build_material(tag: root, user: member_user,
|
||||
file: dummy_upload(filename: 'root.png'))
|
||||
child_a_material =
|
||||
build_material(tag: child_a, user: member_user,
|
||||
file: dummy_upload(filename: 'child_a.png'))
|
||||
grandchild_material =
|
||||
build_material(tag: grandchild, user: member_user,
|
||||
file: dummy_upload(filename: 'grandchild.png'))
|
||||
|
||||
TagImplication.create!(parent_tag: root, tag: child_b)
|
||||
TagImplication.create!(parent_tag: root, tag: child_a)
|
||||
TagImplication.create!(parent_tag: child_b, tag: deprecated)
|
||||
TagImplication.create!(parent_tag: deprecated, tag: grandchild)
|
||||
|
||||
get '/materials',
|
||||
params: { tag_id: root.id, include_descendants: '1',
|
||||
group_by: 'parent_tag', sort: 'id', direction: 'asc' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response_materials.map { |m| m['id'] })
|
||||
.to include(root_material.id, child_a_material.id, grandchild_material.id)
|
||||
expect(json['tag_scope']).to eq(
|
||||
'tag' => {
|
||||
'id' => root.id,
|
||||
'name' => 'material_scope_root',
|
||||
'category' => 'material'
|
||||
},
|
||||
'include_descendants' => true
|
||||
)
|
||||
expect(json['groups'].map { |group| group.dig('tag', 'name') })
|
||||
.to eq(['material_scope_a', 'material_scope_b', 'material_scope_root'])
|
||||
expect(json['groups'].find { |group| group.dig('tag', 'id') == child_b.id }
|
||||
.fetch('material_ids')).to eq([grandchild_material.id])
|
||||
end
|
||||
|
||||
it 'returns nil tag_scope when tag_id is unknown' do
|
||||
get '/materials', params: { tag_id: 999_999, group_by: 'parent_tag' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['tag_scope']).to be_nil
|
||||
expect(json['groups']).to eq([])
|
||||
expect(response_materials).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /materials/:id' do
|
||||
|
||||
新しい課題から参照
ユーザをブロックする