コミットを比較
8 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| 5cf46406a9 | |||
| 29c385ed9f | |||
| abeee76ddd | |||
| 347a0ebbba | |||
| f8e8d8fbb0 | |||
| 33f9c6602f | |||
| 2d6af0aa5b | |||
| c0879ac117 |
@@ -89,13 +89,15 @@ class MaterialsController < ApplicationController
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Material.transaction do
|
Material.transaction do
|
||||||
tag = resolve_material_tag!(tag_name_raw)
|
tag_name = TagName.find_undiscard_or_create_by!(name: tag_name_raw)
|
||||||
|
tag = tag_name.tag
|
||||||
|
tag = Tag.create!(tag_name:, category: :material) unless tag
|
||||||
|
|
||||||
material = Material.new(tag:, url:,
|
material = Material.new(tag:, url:,
|
||||||
created_by_user: current_user,
|
created_by_user: current_user,
|
||||||
updated_by_user: current_user)
|
updated_by_user: current_user)
|
||||||
material.file.attach(uploaded_blob) if uploaded_blob
|
material.file.attach(uploaded_blob) if uploaded_blob
|
||||||
material.save!
|
material.save!
|
||||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
|
||||||
upsert_export_paths!(material)
|
upsert_export_paths!(material)
|
||||||
MaterialVersionRecorder.record!(material:, event_type: :create,
|
MaterialVersionRecorder.record!(material:, event_type: :create,
|
||||||
created_by_user: current_user)
|
created_by_user: current_user)
|
||||||
@@ -137,7 +139,10 @@ class MaterialsController < ApplicationController
|
|||||||
begin
|
begin
|
||||||
Material.transaction do
|
Material.transaction do
|
||||||
MaterialVersionRecorder.ensure_snapshot!(material, created_by_user: current_user)
|
MaterialVersionRecorder.ensure_snapshot!(material, created_by_user: current_user)
|
||||||
tag = resolve_material_tag!(tag_name_raw)
|
tag_name = TagName.find_undiscard_or_create_by!(name: tag_name_raw)
|
||||||
|
tag = tag_name.tag
|
||||||
|
tag = Tag.create!(tag_name:, category: :material) unless tag
|
||||||
|
|
||||||
material.assign_attributes(tag:, url:, updated_by_user: current_user)
|
material.assign_attributes(tag:, url:, updated_by_user: current_user)
|
||||||
if uploaded_blob
|
if uploaded_blob
|
||||||
material.file.attach(uploaded_blob)
|
material.file.attach(uploaded_blob)
|
||||||
@@ -145,7 +150,6 @@ class MaterialsController < ApplicationController
|
|||||||
material.file.detach
|
material.file.detach
|
||||||
end
|
end
|
||||||
material.save!
|
material.save!
|
||||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
|
||||||
upsert_export_paths!(material)
|
upsert_export_paths!(material)
|
||||||
MaterialVersionRecorder.record!(material:, event_type: :update,
|
MaterialVersionRecorder.record!(material:, event_type: :update,
|
||||||
created_by_user: current_user)
|
created_by_user: current_user)
|
||||||
@@ -236,12 +240,6 @@ class MaterialsController < ApplicationController
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_material_tag! tag_name_raw
|
|
||||||
tag_name = TagName.find_undiscard_or_create_by!(name: tag_name_raw)
|
|
||||||
tag = tag_name.tag
|
|
||||||
tag || Tag.create!(tag_name:, category: :material)
|
|
||||||
end
|
|
||||||
|
|
||||||
def material_index_needs_tag_name? filters
|
def material_index_needs_tag_name? filters
|
||||||
filters[:q].present? || filters[:sort] == 'tag_name'
|
filters[:q].present? || filters[:sort] == 'tag_name'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -287,25 +287,6 @@ RSpec.describe 'Materials API', type: :request do
|
|||||||
expect(json.dig('export_paths', 'legacy_drive')).to eq('伊地知ニジカ/created.png')
|
expect(json.dig('export_paths', 'legacy_drive')).to eq('伊地知ニジカ/created.png')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a create tag_version for a newly created material tag' do
|
|
||||||
expect do
|
|
||||||
post '/materials', params: {
|
|
||||||
tag: 'material_create_versioned_tag',
|
|
||||||
file: dummy_upload(filename: 'created.png')
|
|
||||||
}
|
|
||||||
end.to change(TagVersion, :count).by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
|
|
||||||
tag = Tag.joins(:tag_name).find_by!(tag_names: { name: 'material_create_versioned_tag' })
|
|
||||||
version = tag.tag_versions.order(:version_no).last
|
|
||||||
|
|
||||||
expect(version.event_type).to eq('create')
|
|
||||||
expect(version.name).to eq('material_create_versioned_tag')
|
|
||||||
expect(version.category).to eq('material')
|
|
||||||
expect(version.created_by_user).to eq(member_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'snapshots attached file metadata and sha256' do
|
it 'snapshots attached file metadata and sha256' do
|
||||||
post '/materials', params: {
|
post '/materials', params: {
|
||||||
tag: 'material_create_file_version',
|
tag: 'material_create_file_version',
|
||||||
@@ -485,73 +466,6 @@ RSpec.describe 'Materials API', type: :request do
|
|||||||
expect(json.dig('tag', 'name')).to eq('material_update_new')
|
expect(json.dig('tag', 'name')).to eq('material_update_new')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a create tag_version when update creates a new tag' do
|
|
||||||
expect do
|
|
||||||
put "/materials/#{ material.id }", params: {
|
|
||||||
tag: 'material_update_versioned_tag',
|
|
||||||
file: dummy_upload(filename: 'updated.png')
|
|
||||||
}
|
|
||||||
end.to change(Tag, :count).by(1)
|
|
||||||
.and change(TagName, :count).by(1)
|
|
||||||
.and change(TagVersion, :count).by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
|
|
||||||
tag = Tag.joins(:tag_name).find_by!(tag_names: { name: 'material_update_versioned_tag' })
|
|
||||||
version = tag.tag_versions.order(:version_no).last
|
|
||||||
|
|
||||||
expect(version.event_type).to eq('create')
|
|
||||||
expect(version.name).to eq('material_update_versioned_tag')
|
|
||||||
expect(version.category).to eq('material')
|
|
||||||
expect(version.created_by_user).to eq(member_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'backfills a create tag_version for an existing material tag without history' do
|
|
||||||
existing_tag =
|
|
||||||
Tag.create!(tag_name: TagName.create!(name: 'material_update_existing_no_history'),
|
|
||||||
category: :material)
|
|
||||||
|
|
||||||
expect(existing_tag.tag_versions).to be_empty
|
|
||||||
|
|
||||||
expect do
|
|
||||||
put "/materials/#{ material.id }", params: {
|
|
||||||
tag: 'material_update_existing_no_history',
|
|
||||||
file: dummy_upload(filename: 'updated.png')
|
|
||||||
}
|
|
||||||
end.to change(TagVersion, :count).by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
|
|
||||||
version = existing_tag.reload.tag_versions.order(:version_no).last
|
|
||||||
expect(version.event_type).to eq('create')
|
|
||||||
expect(version.name).to eq('material_update_existing_no_history')
|
|
||||||
expect(version.category).to eq('material')
|
|
||||||
expect(version.created_by_user).to eq(member_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'backfills a create tag_version for an existing character tag without history' do
|
|
||||||
existing_tag =
|
|
||||||
Tag.create!(tag_name: TagName.create!(name: 'material_update_character_no_history'),
|
|
||||||
category: :character)
|
|
||||||
|
|
||||||
expect(existing_tag.tag_versions).to be_empty
|
|
||||||
|
|
||||||
expect do
|
|
||||||
put "/materials/#{ material.id }", params: {
|
|
||||||
tag: 'material_update_character_no_history',
|
|
||||||
file: dummy_upload(filename: 'updated.png')
|
|
||||||
}
|
|
||||||
end.to change(TagVersion, :count).by(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
|
||||||
|
|
||||||
version = existing_tag.reload.tag_versions.order(:version_no).last
|
|
||||||
expect(version.event_type).to eq('create')
|
|
||||||
expect(version.name).to eq('material_update_character_no_history')
|
|
||||||
expect(version.category).to eq('character')
|
|
||||||
expect(version.created_by_user).to eq(member_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'detaches the existing file without purging blob when url replaces file' do
|
it 'detaches the existing file without purging blob when url replaces file' do
|
||||||
old_blob_id = material.file.blob.id
|
old_blob_id = material.file.blob.id
|
||||||
|
|
||||||
@@ -580,7 +494,6 @@ RSpec.describe 'Materials API', type: :request do
|
|||||||
it 'does not increase version for the same snapshot update' do
|
it 'does not increase version for the same snapshot update' do
|
||||||
MaterialVersionRecorder.record!(material:, event_type: :create,
|
MaterialVersionRecorder.record!(material:, event_type: :create,
|
||||||
created_by_user: member_user)
|
created_by_user: member_user)
|
||||||
TagVersioning.ensure_snapshot!(tag, created_by_user: member_user)
|
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
put "/materials/#{ material.id }", params: {
|
put "/materials/#{ material.id }", params: {
|
||||||
@@ -588,8 +501,6 @@ RSpec.describe 'Materials API', type: :request do
|
|||||||
}
|
}
|
||||||
end.not_to change(MaterialVersion, :count)
|
end.not_to change(MaterialVersion, :count)
|
||||||
|
|
||||||
expect(tag.reload.tag_versions.count).to eq(1)
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
expect(material.reload.version_no).to eq(1)
|
expect(material.reload.version_no).to eq(1)
|
||||||
end
|
end
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする