ファイル
btrc-hub/backend/spec/models/user_spec.rb
T
2026-10-16 00:15:21 +09:00

26 行
1.2 KiB
Ruby

require 'rails_helper'
RSpec.describe User, type: :model do
it 'nullifies description authorship without deleting native content or history' do
author = create_member_user!
editor = create_member_user!
tag = create(:tag)
description = TagDescriptionOperation.create!(
Locale.nipponese, tag:, body: 'initial', created_by_user: author)
TagDescriptionOperation.update!(
Locale.nipponese, tag:, body: 'edited', updated_by_user: editor)
versions = TagDescriptionVersion.where(tag_id: tag.id).order(:version_no)
snapshots = versions.map(&:attributes)
expect(author.created_tag_descriptions).to contain_exactly(description)
expect(editor.updated_tag_descriptions).to contain_exactly(description)
expect { author.destroy! }.to change(TagDescription, :count).by(0)
.and change(TagDescriptionVersion, :count).by(0)
expect(description.reload).to have_attributes(
body: 'edited', created_by_user_id: nil, updated_by_user_id: editor.id)
expect { editor.destroy! }.not_to change(TagDescription, :count)
expect(description.reload.updated_by_user_id).to be_nil
expect(versions.reload.map(&:attributes)).to eq(snapshots)
end
end