このコミットが含まれているのは:
@@ -13,17 +13,19 @@ RSpec.describe Locale, type: :model do
|
||||
end
|
||||
|
||||
it 'generates a primary name for every existing tag using the name generator' do
|
||||
first = create(:tag, name: 'first_existing_tag')
|
||||
second = create(:tag, name: 'second_existing_tag')
|
||||
first = create(:tag, primary_name: 'first_existing_tag')
|
||||
second = create(:tag, primary_name: 'second_existing_tag')
|
||||
allow(TagName).to receive(:generate_name).and_call_original
|
||||
allow(TagName).to receive(:generate_name)
|
||||
.with(kind_of(described_class), first, first.name)
|
||||
.with(kind_of(described_class), first, primary_tag_name_for(first, 'ja').name)
|
||||
.and_return('name_from_generator')
|
||||
|
||||
locale = create_french_locale!
|
||||
|
||||
expect(TagName).to have_received(:generate_name).with(locale, first, first.name)
|
||||
expect(TagName).to have_received(:generate_name).with(locale, second, second.name)
|
||||
expect(TagName).to have_received(:generate_name)
|
||||
.with(locale, first, primary_tag_name_for(first, 'ja').name)
|
||||
expect(TagName).to have_received(:generate_name)
|
||||
.with(locale, second, primary_tag_name_for(second, 'ja').name)
|
||||
expect(first.tag_names.find_by!(language_code: 'fr', primary_flg: true))
|
||||
.to have_attributes(name: 'name_from_generator', tag_id: first.id,
|
||||
language_code: 'fr', script_code: 'Latn',
|
||||
@@ -37,7 +39,7 @@ RSpec.describe Locale, type: :model do
|
||||
|
||||
it 'does not duplicate an existing primary name in the new language' do
|
||||
prepare_french_reference!
|
||||
tag = create(:tag, name: 'already_named')
|
||||
tag = create(:tag, primary_name: 'already_named')
|
||||
existing = create(:tag_name, name: 'nom_existant', tag:,
|
||||
language_code: 'fr', script_code: 'Latn')
|
||||
|
||||
@@ -51,7 +53,7 @@ RSpec.describe Locale, type: :model do
|
||||
|
||||
it 'creates a primary name when the language has only an alias' do
|
||||
prepare_french_reference!
|
||||
tag = create(:tag, name: 'alias_only_tag')
|
||||
tag = create(:tag, primary_name: 'alias_only_tag')
|
||||
alias_name = create(:tag_name, :alias, name: 'alias_fr',
|
||||
tag:,
|
||||
language_code: 'fr', script_code: 'Latn')
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe MaterialExportItem, type: :model do
|
||||
let(:user) { create(:user, :member) }
|
||||
let(:tag) { create(:tag, name: 'export_item', category: :material) }
|
||||
let(:tag) { create(:tag, primary_name: 'export_item', category: :material) }
|
||||
let(:material) do
|
||||
Material.create!(tag:, url: 'https://example.com/material',
|
||||
created_by_user: user, updated_by_user: user)
|
||||
|
||||
@@ -18,7 +18,7 @@ RSpec.describe Post, type: :model do
|
||||
expect(post.snapshot_tags_json).to eq([
|
||||
{ 'tag_id' => tag.id,
|
||||
'version_no' => tag.version_no,
|
||||
'name' => tag.name,
|
||||
'name' => primary_tag_name_for(tag, 'ja').name,
|
||||
'category' => tag.category,
|
||||
'sections' => [{ 'begin_ms' => 2000, 'end_ms' => nil }] },
|
||||
{ 'external_tag_id' => external.id }])
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe PostVersion, type: :model do
|
||||
let!(:tag_name) { create(:tag_name, name: 'post_version_spec_tag') }
|
||||
let!(:tag) { create(:tag, tag_name: tag_name, category: :general) }
|
||||
let!(:tag) { create(:tag, primary_tag_name: tag_name, category: :general) }
|
||||
|
||||
let!(:post_record) do
|
||||
Post.create!(title: 'spec post', url: 'https://example.com/post-version-spec').tap do |post|
|
||||
|
||||
@@ -2,8 +2,8 @@ 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')
|
||||
child = create(:tag, primary_name: 'tag_implication_cycle_child')
|
||||
parent = create(:tag, primary_name: 'tag_implication_cycle_parent')
|
||||
|
||||
described_class.create!(tag: child, parent_tag: parent)
|
||||
|
||||
@@ -17,9 +17,9 @@ RSpec.describe TagImplication, type: :model do
|
||||
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')
|
||||
child = create(:tag, primary_name: 'tag_implication_existing_cycle_child')
|
||||
parent = create(:tag, primary_name: 'tag_implication_existing_cycle_parent')
|
||||
ancestor = create(:tag, primary_name: 'tag_implication_existing_cycle_ancestor')
|
||||
|
||||
described_class.create!(tag: parent, parent_tag: ancestor)
|
||||
described_class.insert_all!(
|
||||
|
||||
@@ -50,17 +50,17 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
end
|
||||
|
||||
it 'renames without merging tags or deleting either language identity' do
|
||||
japanese = create(:tag, name: 'foobar')
|
||||
japanese = create(:tag, primary_name: 'foobar')
|
||||
english_name = create(:tag_name, name: 'temporary',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, tag_name: english_name)
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
english_name.update_columns(name: 'foo_bar')
|
||||
|
||||
described_class.apply!
|
||||
|
||||
expect(english_name.reload).to have_attributes(
|
||||
name: 'foobar', language_code: 'en', tag_id: english.id)
|
||||
expect(japanese.reload.tag_name).to have_attributes(
|
||||
expect(primary_tag_name_for(japanese.reload, 'ja')).to have_attributes(
|
||||
name: 'foobar', language_code: 'ja', tag_id: japanese.id)
|
||||
expect(english.reload.tag_name_id).to eq(english_name.id)
|
||||
end
|
||||
@@ -96,15 +96,19 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
|
||||
context 'when the source tag_name has a tag and the existing one has no tag' do
|
||||
let!(:existing) { create(:tag_name, name: 'foobar') }
|
||||
let!(:source_tag) { create(:tag, name: 'tmp', category: :general) }
|
||||
let!(:source_tag_name_id) { source_tag.tag_name_id }
|
||||
let!(:source_tag) { create(:tag, primary_name: 'tmp', category: :general) }
|
||||
let!(:source_tag_name_id) { primary_tag_name_for(source_tag, 'ja').id }
|
||||
|
||||
before do
|
||||
source_tag.tag_name.update_columns(name: 'foo_bar', updated_at: Time.current)
|
||||
primary_tag_name_for(source_tag, 'ja').update_columns(
|
||||
name: 'foo_bar', updated_at: Time.current)
|
||||
end
|
||||
|
||||
it 'moves the tag to the existing tag_name' do
|
||||
described_class.apply!
|
||||
expect(existing.reload).to have_attributes(
|
||||
tag_id: source_tag.id, language_code: 'ja', primary_flg: true)
|
||||
expect(primary_tag_name_for(source_tag, 'ja')).to eq(existing)
|
||||
expect(source_tag.reload.tag_name_id).to eq(existing.id)
|
||||
expect(TagName.unscoped.exists?(source_tag_name_id)).to be(false)
|
||||
end
|
||||
@@ -112,6 +116,7 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
|
||||
context 'when the sanitised name is an alias of an existing tag' do
|
||||
let!(:existing_tag) { create(:tag) }
|
||||
let!(:existing_primary) { primary_tag_name_for(existing_tag, 'ja') }
|
||||
let!(:alias_name) do
|
||||
create(:tag_name, :alias, name: 'foobar', tag: existing_tag)
|
||||
end
|
||||
@@ -129,17 +134,17 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
tag_id: existing_tag.id, language_code: 'ja', primary_flg: false)
|
||||
expect(TagName.find_by!(tag_id: existing_tag.id,
|
||||
language_code: 'ja', primary_flg: true))
|
||||
.to eq(existing_tag.tag_name)
|
||||
.to eq(existing_primary)
|
||||
expect(Tag.find(existing_tag.id)).to eq(existing_tag)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when both source and existing tag_names have tags' do
|
||||
let!(:existing_tn) { create(:tag_name, name: 'foobar') }
|
||||
let!(:existing_tag) { create(:tag, tag_name: existing_tn, category: :general) }
|
||||
let!(:existing_tag) { create(:tag, primary_tag_name: existing_tn, category: :general) }
|
||||
|
||||
let!(:source_tn) { create(:tag_name, name: 'tmp') }
|
||||
let!(:source_tag) { create(:tag, tag_name: source_tn, category: :general) }
|
||||
let!(:source_tag) { create(:tag, primary_tag_name: source_tn, category: :general) }
|
||||
let!(:source_tag_name_id) { source_tn.id }
|
||||
|
||||
before do
|
||||
@@ -155,7 +160,7 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
expect(Tag.unscoped.exists?(source_tag.id)).to be(false)
|
||||
expect(TagName.unscoped.exists?(source_tag_name_id)).to be(false)
|
||||
expect(post.reload.tags).to contain_exactly(existing_tag)
|
||||
expect(existing_tag.reload.name).to eq('foobar')
|
||||
expect(primary_tag_name_for(existing_tag.reload, 'ja').name).to eq('foobar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,16 +28,33 @@ RSpec.describe TagName, type: :model do
|
||||
end
|
||||
|
||||
it 'persists both sides of the representative tag factory association' do
|
||||
tag = create(:tag)
|
||||
name = create(:tag_name)
|
||||
tag = create(:tag, primary_tag_name: name)
|
||||
|
||||
expect(tag.reload.tag_name.reload.tag_id).to eq(tag.id)
|
||||
expect(tag.tag_name.tag).to eq(tag)
|
||||
expect(name.reload).to have_attributes(
|
||||
tag_id: tag.id, language_code: 'ja', script_code: 'Jpan', primary_flg: true)
|
||||
expect(name.tag).to eq(tag)
|
||||
expect(described_class.find_by!(tag_id: tag.id, language_code: 'ja', primary_flg: true))
|
||||
.to eq(tag.tag_name)
|
||||
.to eq(name)
|
||||
expect(tag.reload.tag_name_id).to eq(name.id)
|
||||
end
|
||||
|
||||
it 'builds a primary name without persisting the tag or its name' do
|
||||
tag = nil
|
||||
|
||||
expect {
|
||||
tag = build(:tag, primary_name: 'built_primary')
|
||||
}.to change(Tag, :count).by(0).and change(described_class, :count).by(0)
|
||||
|
||||
expect(tag).to be_new_record
|
||||
expect(tag.tag_names.target).to contain_exactly(have_attributes(
|
||||
name: 'built_primary', language_code: 'ja', script_code: 'Jpan',
|
||||
primary_flg: true))
|
||||
end
|
||||
|
||||
it 'persists an alias owned by the same tag as its primary name' do
|
||||
tag = create(:tag)
|
||||
primary_name = create(:tag_name)
|
||||
tag = create(:tag, primary_tag_name: primary_name)
|
||||
alias_name = create(:tag_name, :alias, name: 'valid_alias', tag:)
|
||||
|
||||
expect(alias_name.reload).to have_attributes(
|
||||
@@ -46,12 +63,12 @@ RSpec.describe TagName, type: :model do
|
||||
primary = described_class.find_by!(tag_id: alias_name.tag_id,
|
||||
language_code: alias_name.language_code,
|
||||
primary_flg: true)
|
||||
expect(primary).to eq(tag.tag_name)
|
||||
expect(primary).to eq(primary_name)
|
||||
end
|
||||
|
||||
describe '.canonicalise' do
|
||||
it 'resolves the primary name of the alias language on the same tag' do
|
||||
tag = create(:tag, name: '日本語正本')
|
||||
tag = create(:tag, primary_name: '日本語正本')
|
||||
english_primary = create(:tag_name, tag:, name: 'english_primary',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english_alias = create(:tag_name, :alias, tag:, name: 'english_alias',
|
||||
@@ -69,10 +86,10 @@ RSpec.describe TagName, type: :model do
|
||||
end
|
||||
|
||||
it 'resolves only aliases in the requested language' do
|
||||
japanese = create(:tag, name: 'japanese_canonical')
|
||||
japanese = create(:tag, primary_name: 'japanese_canonical')
|
||||
english_name = create(:tag_name, name: 'english_canonical',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, tag_name: english_name)
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
english_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe Tag, type: :model do
|
||||
describe 'external tag separation' do
|
||||
['nico:reserved', 'NiCo:reserved'].each do |name|
|
||||
it "rejects the reserved prefix #{ name } for internal tags" do
|
||||
tag = build(:tag, name:)
|
||||
tag = build(:tag, primary_name: name)
|
||||
|
||||
expect(tag).to be_invalid
|
||||
expect(tag.errors[:name]).to be_present
|
||||
@@ -32,10 +32,10 @@ RSpec.describe Tag, type: :model do
|
||||
{ code: 'en', language_code: 'en', script_code: 'Latn',
|
||||
name: 'English', created_at: Time.current }]) unless Locale.exists?(code: 'en')
|
||||
english_locale = Locale.find('en')
|
||||
japanese = create(:tag, name: 'japanese_canonical')
|
||||
japanese = create(:tag, primary_name: 'japanese_canonical')
|
||||
english_name = create(:tag_name, name: 'english_canonical',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, tag_name: english_name)
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
english_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
@@ -59,16 +59,16 @@ RSpec.describe Tag, type: :model do
|
||||
it 'rejects deprecated tags when deny_deprecated is enabled' do
|
||||
tag_name = create(:tag_name, name: 'normalise deprecated tag')
|
||||
deprecated_tag = create(:tag,
|
||||
tag_name:,
|
||||
primary_tag_name: tag_name,
|
||||
category: :general,
|
||||
deprecated_at: 1.day.from_now)
|
||||
|
||||
expect {
|
||||
described_class.normalise_tags!(Locale.nipponese,
|
||||
[deprecated_tag.name],
|
||||
[primary_tag_name_for(deprecated_tag, 'ja').name],
|
||||
deny_deprecated: true)
|
||||
}.to raise_error(Tag::DeprecatedTagNormalisationError) { |error|
|
||||
expect(error.tag_names).to eq([deprecated_tag.name])
|
||||
expect(error.tag_names).to eq([primary_tag_name_for(deprecated_tag, 'ja').name])
|
||||
}
|
||||
end
|
||||
|
||||
@@ -85,7 +85,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[1:00-]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[60_000, nil]])
|
||||
end
|
||||
|
||||
@@ -94,7 +96,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[-1:00]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[0, 60_000]])
|
||||
end
|
||||
|
||||
@@ -103,7 +107,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[-]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections)[tag.id]).to be_nil
|
||||
end
|
||||
|
||||
@@ -112,7 +118,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[0:00-]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections)[tag.id]).to be_nil
|
||||
end
|
||||
|
||||
@@ -121,7 +129,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[1:00-1:00]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[60_000, 60_001]])
|
||||
end
|
||||
|
||||
@@ -130,7 +140,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[2:00-1:00]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[60_000, 120_000]])
|
||||
end
|
||||
|
||||
@@ -139,7 +151,9 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[1:00-][2:00-3:00]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[60_000, nil]])
|
||||
end
|
||||
|
||||
@@ -148,25 +162,23 @@ RSpec.describe Tag, type: :model do
|
||||
['伊地知ニジカ[1:00-3:00][3:00-]'],
|
||||
with_sections: true)
|
||||
|
||||
tag = result.fetch(:tags).find { _1.name == '伊地知ニジカ' }
|
||||
tag = result.fetch(:tags).find do |candidate|
|
||||
primary_tag_name_for(candidate, 'ja').name == '伊地知ニジカ'
|
||||
end
|
||||
expect(result.fetch(:sections).fetch(tag.id)).to eq([[60_000, nil]])
|
||||
end
|
||||
end
|
||||
|
||||
describe '.expand_parent_tags' do
|
||||
it 'expands through multiple deprecated parents to an active ancestor' do
|
||||
child = create(:tag, name: 'expand_child')
|
||||
deprecated_parent = create(
|
||||
:tag,
|
||||
name: 'expand_deprecated_parent',
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
deprecated_grandparent = create(
|
||||
:tag,
|
||||
name: 'expand_deprecated_grandparent',
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
active_ancestor = create(:tag, name: 'expand_active_ancestor')
|
||||
child = create(:tag, primary_name: 'expand_child')
|
||||
deprecated_parent = create(:tag,
|
||||
primary_name: 'expand_deprecated_parent',
|
||||
deprecated_at: Time.current)
|
||||
deprecated_grandparent = create(:tag,
|
||||
primary_name: 'expand_deprecated_grandparent',
|
||||
deprecated_at: Time.current)
|
||||
active_ancestor = create(:tag, primary_name: 'expand_active_ancestor')
|
||||
TagImplication.create!(tag: child, parent_tag: deprecated_parent)
|
||||
TagImplication.create!(tag: deprecated_parent, parent_tag: deprecated_grandparent)
|
||||
TagImplication.create!(tag: deprecated_grandparent, parent_tag: active_ancestor)
|
||||
@@ -183,8 +195,8 @@ RSpec.describe Tag, type: :model do
|
||||
end
|
||||
|
||||
it 'terminates when implications contain a cycle' do
|
||||
first = create(:tag, name: 'expand_cycle_first')
|
||||
second = create(:tag, name: 'expand_cycle_second')
|
||||
first = create(:tag, primary_name: 'expand_cycle_first')
|
||||
second = create(:tag, primary_name: 'expand_cycle_second')
|
||||
TagImplication.create!(tag: first, parent_tag: second)
|
||||
now = Time.current
|
||||
TagImplication.insert_all!(
|
||||
@@ -210,7 +222,7 @@ RSpec.describe Tag, type: :model do
|
||||
tag = described_class.find_or_create_by_tag_name!(
|
||||
locale, 'english_name', category: :character)
|
||||
|
||||
expect(tag.tag_name.reload).to have_attributes(
|
||||
expect(primary_tag_name_for(tag, 'en')).to have_attributes(
|
||||
language_code: 'en', script_code: 'Latn',
|
||||
primary_flg: true, tag_id: tag.id)
|
||||
expect(tag.category).to eq('character')
|
||||
@@ -223,8 +235,10 @@ RSpec.describe Tag, type: :model do
|
||||
locale, 'same_name', category: :character)
|
||||
|
||||
expect(english).not_to eq(japanese)
|
||||
expect(english.tag_name.language_code).to eq('en')
|
||||
expect(japanese.tag_name.language_code).to eq('ja')
|
||||
expect(primary_tag_name_for(english, 'en')).to have_attributes(
|
||||
name: 'same_name', tag_id: english.id, language_code: 'en', primary_flg: true)
|
||||
expect(primary_tag_name_for(japanese, 'ja')).to have_attributes(
|
||||
name: 'same_name', tag_id: japanese.id, language_code: 'ja', primary_flg: true)
|
||||
expect(described_class.find_or_create_by_tag_name!(
|
||||
locale, 'same_name', category: :general)).to eq(english)
|
||||
expect(described_class.find_or_create_by_tag_name!(
|
||||
@@ -232,7 +246,7 @@ RSpec.describe Tag, type: :model do
|
||||
end
|
||||
|
||||
it 'preserves the V1 representative when looking up another primary language' do
|
||||
tag = create(:tag, name: '日本語代表名')
|
||||
tag = create(:tag, primary_name: '日本語代表名')
|
||||
representative_id = tag.tag_name_id
|
||||
english = create(:tag_name, name: 'english_primary', tag:,
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
@@ -251,7 +265,7 @@ RSpec.describe Tag, type: :model do
|
||||
with_tagme: false, with_no_deerjikist: false)
|
||||
|
||||
expect(tags.length).to eq(1)
|
||||
expect(tags.first.tag_name).to have_attributes(
|
||||
expect(primary_tag_name_for(tags.first, 'en')).to have_attributes(
|
||||
name: 'normalised_english', language_code: 'en', script_code: 'Latn',
|
||||
primary_flg: true, tag_id: tags.first.id)
|
||||
end
|
||||
@@ -265,7 +279,7 @@ RSpec.describe Tag, type: :model do
|
||||
' lookup_new ', category: :character)
|
||||
}.to change(Tag, :count).by(1).and change(TagName, :count).by(1)
|
||||
|
||||
expect(tag.name).to eq('lookup_new')
|
||||
expect(primary_tag_name_for(tag, 'ja').name).to eq('lookup_new')
|
||||
expect(tag.category).to eq('character')
|
||||
end
|
||||
|
||||
@@ -290,7 +304,7 @@ RSpec.describe Tag, type: :model do
|
||||
|
||||
it 'reuses the owning tag through another alias' do
|
||||
tag = create(:tag)
|
||||
primary = tag.tag_name
|
||||
primary = primary_tag_name_for(tag, 'ja')
|
||||
alias_name = create(:tag_name, :alias, name: 'lookup_alias', tag:)
|
||||
other_alias = create(:tag_name, :alias, name: 'lookup_other_alias', tag:)
|
||||
|
||||
@@ -304,14 +318,14 @@ RSpec.describe Tag, type: :model do
|
||||
expect(found).to eq(tag)
|
||||
}.to change(Tag, :count).by(0).and change(TagName, :count).by(0)
|
||||
|
||||
expect(tag.reload.tag_name).to eq(primary)
|
||||
expect(primary_tag_name_for(tag.reload, 'ja')).to eq(primary)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.merge_tags!' do
|
||||
let!(:target_tag) { create(:tag, category: :general) }
|
||||
let!(:source_tag) { create(:tag, category: :general) }
|
||||
let!(:source_tag_name) { source_tag.tag_name }
|
||||
let!(:source_tag_name) { primary_tag_name_for(source_tag, 'ja') }
|
||||
|
||||
let!(:post_record) do
|
||||
Post.create!(url: 'https://example.com/posts/1', title: 'test post')
|
||||
@@ -363,7 +377,7 @@ RSpec.describe Tag, type: :model do
|
||||
|
||||
it 'keeps source history and records the new target alias after deleting the source' do
|
||||
user = create_member_user!
|
||||
source_name = source_tag.name
|
||||
source_name = primary_tag_name_for(source_tag, 'ja').name
|
||||
source_alias = create(:tag_name, :alias, name: 'merge_alias', tag: source_tag)
|
||||
TagVersioning.ensure_snapshot!(source_tag, created_by_user: user)
|
||||
original_version = source_tag.tag_versions.first
|
||||
@@ -380,7 +394,7 @@ RSpec.describe Tag, type: :model do
|
||||
|
||||
target_versions = target_tag.tag_versions.order(:version_no)
|
||||
expect(target_versions.pluck(:event_type)).to eq(['create', 'update'])
|
||||
expect(target_versions.last.aliases.split).to eq([source_name])
|
||||
expect(target_versions.last.aliases.split).to contain_exactly('merge_alias', source_name)
|
||||
end
|
||||
|
||||
it 'deletes source relationships while preserving unrelated relationships' do
|
||||
@@ -486,7 +500,7 @@ RSpec.describe Tag, type: :model do
|
||||
|
||||
it 'rolls back earlier deletions, links, and history when a later source has a wiki' do
|
||||
earlier_source = create(:tag)
|
||||
earlier_name = earlier_source.tag_name
|
||||
earlier_name = primary_tag_name_for(earlier_source, 'ja')
|
||||
source_section = create(:post_tag_section, post: post_record,
|
||||
tag: source_tag,
|
||||
begin_ms: 1000, end_ms: 2000)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe VersionRecord, type: :model do
|
||||
let!(:tag) { create(:tag, name: 'version_record_tag') }
|
||||
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
|
||||
@@ -9,7 +9,7 @@ RSpec.describe VersionRecord, type: :model do
|
||||
tag: tag,
|
||||
version_no: 1,
|
||||
event_type: 'create',
|
||||
name: tag.name,
|
||||
name: primary_tag_name_for(tag, 'ja').name,
|
||||
category: tag.category,
|
||||
aliases: '',
|
||||
parent_tag_ids: '',
|
||||
@@ -27,7 +27,7 @@ RSpec.describe VersionRecord, type: :model do
|
||||
tag: tag,
|
||||
version_no: 1,
|
||||
event_type: 'create',
|
||||
name: tag.name,
|
||||
name: primary_tag_name_for(tag, 'ja').name,
|
||||
category: tag.category,
|
||||
aliases: '',
|
||||
parent_tag_ids: '',
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする