87 行
2.4 KiB
Ruby
87 行
2.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe VersionRecord, type: :model do
|
|
let!(:tag) { create(:tag, primary_name: 'version_record_tag') }
|
|
let!(:nico_tag) { create(:external_tag, name: 'version_record_tag') }
|
|
|
|
it 'makes TagVersion read only after create' do
|
|
version = TagVersion.create!(
|
|
tag: tag,
|
|
version_no: 1,
|
|
event_type: 'create',
|
|
name: primary_tag_name_for(tag, 'ja').name,
|
|
category: tag.category,
|
|
aliases: '',
|
|
names: { ja: { name: primary_tag_name_for(tag, 'ja').name,
|
|
script_code: 'Jpan', auto_generated: false, aliases: [] } },
|
|
parent_tag_ids: '',
|
|
created_at: Time.current,
|
|
created_by_user: nil)
|
|
|
|
expect {
|
|
version.update!(name: 'changed')
|
|
}.to raise_error(ActiveRecord::ReadOnlyRecord)
|
|
end
|
|
|
|
it 'prevents TagVersion destroy' do
|
|
version = TagVersion.create!(
|
|
tag: tag,
|
|
version_no: 1,
|
|
event_type: 'create',
|
|
name: primary_tag_name_for(tag, 'ja').name,
|
|
category: tag.category,
|
|
aliases: '',
|
|
names: { ja: { name: primary_tag_name_for(tag, 'ja').name,
|
|
script_code: 'Jpan', auto_generated: false, aliases: [] } },
|
|
parent_tag_ids: '',
|
|
created_at: Time.current,
|
|
created_by_user: nil)
|
|
|
|
expect {
|
|
version.destroy!
|
|
}.to raise_error(ActiveRecord::ReadOnlyRecord)
|
|
end
|
|
|
|
it 'makes NicoTagVersion read only after create' do
|
|
version = NicoTagVersion.create!(
|
|
external_tag: nico_tag,
|
|
version_no: 1,
|
|
event_type: 'create',
|
|
linked_tag_ids: '',
|
|
created_at: Time.current,
|
|
created_by_user: nil
|
|
)
|
|
|
|
expect {
|
|
version.update!(linked_tag_ids: '123')
|
|
}.to raise_error(ActiveRecord::ReadOnlyRecord)
|
|
end
|
|
|
|
|
|
it 'rejects discard and restore versions for external tags' do
|
|
[:discard, :restore].each do |event_type|
|
|
version = NicoTagVersion.new(
|
|
external_tag: nico_tag, version_no: 1, event_type:,
|
|
linked_tag_ids: '', created_at: Time.current)
|
|
|
|
expect(version).not_to be_valid
|
|
expect(version.errors[:event_type]).not_to be_empty
|
|
end
|
|
end
|
|
|
|
it 'prevents NicoTagVersion destroy' do
|
|
version = NicoTagVersion.create!(
|
|
external_tag: nico_tag,
|
|
version_no: 1,
|
|
event_type: 'create',
|
|
linked_tag_ids: '',
|
|
created_at: Time.current,
|
|
created_by_user: nil
|
|
)
|
|
|
|
expect {
|
|
version.destroy!
|
|
}.to raise_error(ActiveRecord::ReadOnlyRecord)
|
|
end
|
|
end
|