このコミットが含まれているのは:
@@ -17,22 +17,23 @@ RSpec.describe Locale, type: :model do
|
||||
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, primary_tag_name_for(first, 'ja').name)
|
||||
.with(kind_of(described_class), first, primary_tag_name_for(first, 'ja'))
|
||||
.and_return('name_from_generator')
|
||||
|
||||
locale = create_french_locale!
|
||||
|
||||
expect(TagName).to have_received(:generate_name)
|
||||
.with(locale, first, primary_tag_name_for(first, 'ja').name)
|
||||
.with(locale, first, primary_tag_name_for(first, 'ja'))
|
||||
expect(TagName).to have_received(:generate_name)
|
||||
.with(locale, second, primary_tag_name_for(second, 'ja').name)
|
||||
.with(locale, second, primary_tag_name_for(second, 'ja'))
|
||||
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',
|
||||
primary_flg: true)
|
||||
primary_flg: true, auto_generated: true)
|
||||
expect(second.tag_names.find_by!(language_code: 'fr', primary_flg: true))
|
||||
.to have_attributes(tag_id: second.id, language_code: 'fr',
|
||||
script_code: 'Latn', primary_flg: true)
|
||||
script_code: 'Latn', primary_flg: true,
|
||||
auto_generated: true)
|
||||
expect(TagName.where(language_code: 'fr', primary_flg: true,
|
||||
tag_id: [first.id, second.id]).count).to eq(2)
|
||||
end
|
||||
@@ -48,7 +49,8 @@ RSpec.describe Locale, type: :model do
|
||||
expect(TagName.where(tag_id: tag.id, language_code: 'fr', primary_flg: true))
|
||||
.to contain_exactly(existing)
|
||||
expect(existing.reload).to have_attributes(
|
||||
tag_id: tag.id, language_code: 'fr', script_code: 'Latn', primary_flg: true)
|
||||
tag_id: tag.id, language_code: 'fr', script_code: 'Latn',
|
||||
primary_flg: true, auto_generated: false)
|
||||
end
|
||||
|
||||
it 'creates a primary name when the language has only an alias' do
|
||||
@@ -65,7 +67,8 @@ RSpec.describe Locale, type: :model do
|
||||
language_code: 'fr', script_code: 'Latn', primary_flg: false)
|
||||
generated = TagName.find_by!(tag_id: tag.id, language_code: 'fr', primary_flg: true)
|
||||
expect(generated).to have_attributes(tag_id: tag.id, language_code: 'fr',
|
||||
script_code: 'Latn', primary_flg: true)
|
||||
script_code: 'Latn', primary_flg: true,
|
||||
auto_generated: true)
|
||||
expect(TagName.where(tag_id: tag.id, language_code: 'fr', primary_flg: true).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,14 +31,14 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
|
||||
describe '.apply!' do
|
||||
before do
|
||||
described_class.create!(priority: 10, source_pattern: '_', replacement: '')
|
||||
described_class.create!(priority: 10, source_pattern: 'foo_', replacement: 'foo')
|
||||
end
|
||||
|
||||
context 'when only another language has the sanitised name' do
|
||||
include_context 'English locale'
|
||||
|
||||
it 'keeps both names when sanitisation produces a cross-language match' do
|
||||
japanese = create(:tag_name, name: 'foobar')
|
||||
nipponese = create(:tag_name, name: 'foobar')
|
||||
english = create(:tag_name, name: 'temporary',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english.update_columns(name: 'foo_bar')
|
||||
@@ -46,11 +46,11 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
expect { described_class.apply! }.not_to change(TagName, :count)
|
||||
|
||||
expect(english.reload).to have_attributes(name: 'foobar', language_code: 'en')
|
||||
expect(japanese.reload).to have_attributes(name: 'foobar', language_code: 'ja')
|
||||
expect(nipponese.reload).to have_attributes(name: 'foobar', language_code: 'ja')
|
||||
end
|
||||
|
||||
it 'renames without merging tags or deleting either language identity' do
|
||||
japanese = create(:tag, primary_name: 'foobar')
|
||||
nipponese = create(:tag, primary_name: 'foobar')
|
||||
english_name = create(:tag_name, name: 'temporary',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
@@ -60,8 +60,8 @@ RSpec.describe TagNameSanitisationRule, type: :model do
|
||||
|
||||
expect(english_name.reload).to have_attributes(
|
||||
name: 'foobar', language_code: 'en', tag_id: english.id)
|
||||
expect(primary_tag_name_for(japanese.reload, 'ja')).to have_attributes(
|
||||
name: 'foobar', language_code: 'ja', tag_id: japanese.id)
|
||||
expect(primary_tag_name_for(nipponese.reload, 'ja')).to have_attributes(
|
||||
name: 'foobar', language_code: 'ja', tag_id: nipponese.id)
|
||||
expect(primary_tag_name_for(english.reload, 'en')).to eq(english_name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ RSpec.describe TagName, type: :model do
|
||||
expect(duplicate.errors.of_kind?(:name, :taken)).to be(true)
|
||||
end
|
||||
|
||||
it 'creates Japanese factory names without requiring a tag' do
|
||||
it 'creates Nipponese factory names without requiring a tag' do
|
||||
name = create(:tag_name)
|
||||
|
||||
expect(name.reload).to have_attributes(
|
||||
@@ -74,15 +74,6 @@ RSpec.describe TagName, type: :model do
|
||||
.to eq(['detached_alias'])
|
||||
end
|
||||
|
||||
it 'leaves an alias unchanged when its language has no primary' do
|
||||
tag = create(:tag, primary_name: '日本語のみ')
|
||||
create(:tag_name, :alias, tag:, name: 'orphan_english_alias',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
|
||||
expect(described_class.canonicalise(locale, ['orphan_english_alias']))
|
||||
.to eq(['orphan_english_alias'])
|
||||
end
|
||||
|
||||
it 'resolves the primary name of the alias language on the same tag' do
|
||||
tag = create(:tag, primary_name: '日本語正本')
|
||||
english_primary = create(:tag_name, tag:, name: 'english_primary',
|
||||
@@ -102,18 +93,18 @@ RSpec.describe TagName, type: :model do
|
||||
end
|
||||
|
||||
it 'resolves only aliases in the requested language' do
|
||||
japanese = create(:tag, primary_name: 'japanese_canonical')
|
||||
nipponese = create(:tag, primary_name: 'nipponese_canonical')
|
||||
english_name = create(:tag_name, name: 'english_canonical',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
nipponese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: nipponese)
|
||||
english_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: english,
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
|
||||
expect(japanese_alias.reload).to have_attributes(
|
||||
tag_id: japanese.id,
|
||||
expect(nipponese_alias.reload).to have_attributes(
|
||||
tag_id: nipponese.id,
|
||||
primary_flg: false, language_code: 'ja')
|
||||
expect(english_alias.reload).to have_attributes(
|
||||
tag_id: english.id,
|
||||
@@ -121,7 +112,7 @@ RSpec.describe TagName, type: :model do
|
||||
expect(described_class.canonicalise(locale, ['shared_alias']))
|
||||
.to eq(['english_canonical'])
|
||||
expect(described_class.canonicalise(Locale.nipponese, ['shared_alias']))
|
||||
.to eq(['japanese_canonical'])
|
||||
.to eq(['nipponese_canonical'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,22 +28,21 @@ RSpec.describe Tag, type: :model do
|
||||
it 'canonicalises aliases in the supplied language only' do
|
||||
Language.find_or_create_by!(code: 'en') { _1.name = 'English' }
|
||||
Script.find_or_create_by!(code: 'Latn') { _1.name = 'Latin' }
|
||||
Locale.insert_all!([
|
||||
{ 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, primary_name: 'japanese_canonical')
|
||||
nipponese = create(:tag, primary_name: 'nipponese_canonical')
|
||||
english_name = create(:tag_name, name: 'english_canonical',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, primary_tag_name: english_name)
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
create(:tag_name, tag: english, name: 'english_in_nipponese')
|
||||
english_locale = Locale.create!(
|
||||
code: 'en', language_code: 'en', script_code: 'Latn', name: 'English')
|
||||
nipponese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: nipponese)
|
||||
english_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: english,
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
|
||||
expect(japanese_alias.reload).to have_attributes(
|
||||
tag_id: japanese.id,
|
||||
expect(nipponese_alias.reload).to have_attributes(
|
||||
tag_id: nipponese.id,
|
||||
primary_flg: false, language_code: 'ja')
|
||||
expect(english_alias.reload).to have_attributes(
|
||||
tag_id: english.id,
|
||||
@@ -53,7 +52,7 @@ RSpec.describe Tag, type: :model do
|
||||
with_tagme: false, with_no_deerjikist: false)).to eq([english])
|
||||
expect(described_class.normalise_tags!(
|
||||
Locale.nipponese, ['shared_alias'],
|
||||
with_tagme: false, with_no_deerjikist: false)).to eq([japanese])
|
||||
with_tagme: false, with_no_deerjikist: false)).to eq([nipponese])
|
||||
end
|
||||
|
||||
it 'rejects deprecated tags when deny_deprecated is enabled' do
|
||||
@@ -228,21 +227,46 @@ RSpec.describe Tag, type: :model do
|
||||
expect(tag.category).to eq('character')
|
||||
end
|
||||
|
||||
it 'uses the English primary as the source for a generated Nipponese name' do
|
||||
allow(TagName).to receive(:generate_name).and_return('generated_nipponese')
|
||||
|
||||
tag = described_class.find_or_create_by_tag_name!(
|
||||
locale, 'english_origin', category: :general)
|
||||
|
||||
expect(TagName.where(tag:, language_code: 'en', primary_flg: true))
|
||||
.to contain_exactly(have_attributes(
|
||||
name: 'english_origin', auto_generated: false))
|
||||
expect(TagName.where(tag:, language_code: 'ja', primary_flg: true))
|
||||
.to contain_exactly(have_attributes(
|
||||
name: 'generated_nipponese', auto_generated: true))
|
||||
source_tag_name = TagName.find_by!(tag:, language_code: 'en', primary_flg: true)
|
||||
expect(TagName).to have_received(:generate_name)
|
||||
.with(Locale.nipponese, tag, source_tag_name)
|
||||
end
|
||||
|
||||
it 'gives a new tag one primary name for every active language' do
|
||||
tag = described_class.find_or_create_by_tag_name!(
|
||||
Locale.nipponese, 'new_multilingual_tag', category: :general)
|
||||
|
||||
expect(TagName.where(tag:, language_code: 'ja', primary_flg: true).count).to eq(1)
|
||||
expect(TagName.where(tag:, language_code: 'en', primary_flg: true).count).to eq(1)
|
||||
end
|
||||
|
||||
it 'creates separate tag identities for the same name in different languages' do
|
||||
japanese = described_class.find_or_create_by_tag_name!(
|
||||
nipponese = described_class.find_or_create_by_tag_name!(
|
||||
Locale.nipponese, 'same_name', category: :general)
|
||||
english = described_class.find_or_create_by_tag_name!(
|
||||
locale, 'same_name', category: :character)
|
||||
|
||||
expect(english).not_to eq(japanese)
|
||||
expect(english).not_to eq(nipponese)
|
||||
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(primary_tag_name_for(nipponese, 'ja')).to have_attributes(
|
||||
name: 'same_name', tag_id: nipponese.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!(
|
||||
Locale.nipponese, 'same_name', category: :general)).to eq(japanese)
|
||||
Locale.nipponese, 'same_name', category: :general)).to eq(nipponese)
|
||||
end
|
||||
|
||||
it 'preserves the V1 representative when looking up another primary language' do
|
||||
@@ -335,33 +359,25 @@ RSpec.describe Tag, type: :model do
|
||||
include_context 'English locale'
|
||||
|
||||
it 'keeps the target primary and moves source names as aliases' do
|
||||
english_primary = create(:tag_name, tag: target_tag,
|
||||
name: 'target_english', language_code: 'en', script_code: 'Latn')
|
||||
source_primary = create(:tag_name, tag: source_tag,
|
||||
name: 'source_english', language_code: 'en', script_code: 'Latn')
|
||||
english_primary = primary_tag_name_for(target_tag, 'en')
|
||||
source_primary = primary_tag_name_for(source_tag, 'en')
|
||||
source_alias = create(:tag_name, :alias, tag: source_tag,
|
||||
name: 'source_english_alias', language_code: 'en', script_code: 'Latn')
|
||||
|
||||
expect([english_primary, source_primary]).to all(have_attributes(
|
||||
primary_flg: true, auto_generated: true))
|
||||
|
||||
described_class.merge_tags!(target_tag, [source_tag])
|
||||
|
||||
expect(primary_tag_name_for(target_tag.reload, 'en')).to eq(english_primary)
|
||||
expect(TagName.where(tag: target_tag, language_code: 'en', primary_flg: true))
|
||||
.to contain_exactly(english_primary)
|
||||
expect([source_primary.reload, source_alias.reload]).to all(have_attributes(
|
||||
tag_id: target_tag.id, language_code: 'en', primary_flg: false))
|
||||
end
|
||||
|
||||
it 'inherits a source primary when the target has no name in that language' do
|
||||
source_primary = create(:tag_name, tag: source_tag,
|
||||
name: 'inherited_english', language_code: 'en', script_code: 'Latn')
|
||||
source_alias = create(:tag_name, :alias, tag: source_tag,
|
||||
name: 'inherited_alias', language_code: 'en', script_code: 'Latn')
|
||||
|
||||
described_class.merge_tags!(target_tag, [source_tag])
|
||||
|
||||
expect(primary_tag_name_for(target_tag.reload, 'en')).to eq(source_primary)
|
||||
expect(source_primary.reload).to have_attributes(
|
||||
tag_id: target_tag.id, language_code: 'en', primary_flg: true)
|
||||
expect(source_alias.reload).to have_attributes(
|
||||
tag_id: target_tag.id, language_code: 'en', primary_flg: false)
|
||||
expect(TagName.where(tag: target_tag, language_code: 'ja', primary_flg: true))
|
||||
.to contain_exactly(primary_tag_name_for(target_tag, 'ja'))
|
||||
expect(source_tag_name.reload).to have_attributes(
|
||||
tag_id: target_tag.id, language_code: 'ja', primary_flg: false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
let(:locale_params) { requested_locale ? { locale: requested_locale } : { } }
|
||||
let(:expected_locale) { requested_locale ? locale : Locale.nipponese }
|
||||
|
||||
it 'creates post tags in the requested language or Japanese fallback' do
|
||||
it 'creates post tags in the requested language or Nipponese fallback' do
|
||||
post '/posts', params: locale_params.merge(
|
||||
title: 'Locale post', url: 'https://example.com/locale-post',
|
||||
tags: 'locale_post_tag', parent_post_ids: '')
|
||||
@@ -32,7 +32,7 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
expect(Post.find(json.fetch('id')).tags).to include(tag)
|
||||
end
|
||||
|
||||
it 'updates post tags in the requested language or Japanese fallback' do
|
||||
it 'updates post tags in the requested language or Nipponese fallback' do
|
||||
record = create(:post)
|
||||
PostVersionRecorder.record!(post: record, event_type: :create, created_by_user: member)
|
||||
|
||||
@@ -110,8 +110,8 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
create(:tag_name, name: 'shared_name', language_code: 'en', script_code: 'Latn')
|
||||
end
|
||||
let!(:english_tag) { create(:tag, primary_tag_name: english_name, category: :material) }
|
||||
let!(:japanese_tag) do
|
||||
create(:tag, primary_name: 'temporary_japanese', category: :general).tap do |tag|
|
||||
let!(:nipponese_tag) do
|
||||
create(:tag, primary_name: 'temporary_nipponese', category: :general).tap do |tag|
|
||||
# Isolate lookup from the separately tested uniqueness validation.
|
||||
primary_tag_name_for(tag, 'ja').update_columns(name: 'shared_name')
|
||||
end
|
||||
@@ -125,9 +125,9 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
expect(response).to have_http_status(:created), response.body
|
||||
record = Post.find(json.fetch('id'))
|
||||
expect(record.tags).to include(english_tag)
|
||||
expect(record.tags).not_to include(japanese_tag)
|
||||
expect(record.tags).not_to include(nipponese_tag)
|
||||
expect(english_tag.reload.category).to eq('material')
|
||||
expect(japanese_tag.reload.category).to eq('general')
|
||||
expect(nipponese_tag.reload.category).to eq('general')
|
||||
end
|
||||
|
||||
it 'updates the post using the English identity' do
|
||||
@@ -140,7 +140,7 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:ok), response.body
|
||||
expect(record.reload.tags).to include(english_tag)
|
||||
expect(record.tags).not_to include(japanese_tag)
|
||||
expect(record.tags).not_to include(nipponese_tag)
|
||||
end
|
||||
|
||||
it 'resolves the English material tag' do
|
||||
@@ -149,7 +149,7 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:created), response.body
|
||||
expect(Material.find(json.fetch('id')).tag).to eq(english_tag)
|
||||
expect(Material.where(tag: japanese_tag)).to be_empty
|
||||
expect(Material.where(tag: nipponese_tag)).to be_empty
|
||||
end
|
||||
|
||||
it 'resolves the English parent tag' do
|
||||
@@ -182,16 +182,16 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
end
|
||||
let!(:tag) { create(:tag, primary_tag_name: english_name) }
|
||||
|
||||
it 'allows a rename to a name already used in Japanese' do
|
||||
japanese = create(:tag, primary_name: 'rename_target')
|
||||
it 'allows a rename to a name already used in Nipponese' do
|
||||
nipponese = create(:tag, primary_name: 'rename_target')
|
||||
|
||||
patch "/tags/#{ tag.id }", params: { locale: 'en', name: 'rename_target' }
|
||||
|
||||
expect(response).to have_http_status(:ok), response.body
|
||||
expect(primary_tag_name_for(tag.reload, 'en')).to have_attributes(
|
||||
name: 'rename_target', language_code: 'en', tag_id: tag.id)
|
||||
expect(primary_tag_name_for(japanese.reload, 'ja')).to have_attributes(
|
||||
name: 'rename_target', language_code: 'ja', tag_id: japanese.id)
|
||||
expect(primary_tag_name_for(nipponese.reload, 'ja')).to have_attributes(
|
||||
name: 'rename_target', language_code: 'ja', tag_id: nipponese.id)
|
||||
end
|
||||
|
||||
it 'creates aliases in the requested language' do
|
||||
@@ -210,11 +210,11 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
end
|
||||
|
||||
it 'does not take an alias from another language' do
|
||||
japanese = create(:tag, primary_name: 'japanese_owner')
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
expect(japanese_alias.reload).to have_attributes(
|
||||
tag_id: japanese.id,
|
||||
nipponese = create(:tag, primary_name: 'nipponese_owner')
|
||||
nipponese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: nipponese)
|
||||
expect(nipponese_alias.reload).to have_attributes(
|
||||
tag_id: nipponese.id,
|
||||
primary_flg: false, language_code: 'ja')
|
||||
|
||||
put "/tags/#{ tag.id }", params: {
|
||||
@@ -223,15 +223,15 @@ RSpec.describe 'Locale propagation on write paths', type: :request do
|
||||
aliases: 'shared_alias', parent_tags: '' }
|
||||
|
||||
expect(response).to have_http_status(:ok), response.body
|
||||
expect(japanese_alias.reload).to have_attributes(
|
||||
tag_id: japanese.id,
|
||||
expect(nipponese_alias.reload).to have_attributes(
|
||||
tag_id: nipponese.id,
|
||||
primary_flg: false, language_code: 'ja')
|
||||
expect(TagName.find_by!(language_code: 'en', name: 'shared_alias'))
|
||||
.to have_attributes(
|
||||
tag_id: tag.id, script_code: 'Latn',
|
||||
primary_flg: false, language_code: 'en')
|
||||
expect(TagName.where(name: 'shared_alias').pluck(:language_code, :tag_id))
|
||||
.to contain_exactly(['ja', japanese.id], ['en', tag.id])
|
||||
.to contain_exactly(['ja', nipponese.id], ['en', tag.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,16 +17,16 @@ RSpec.describe PostCreatePlan do
|
||||
english_name = create(:tag_name, name: 'shared_name',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, primary_tag_name: english_name, category: :character)
|
||||
japanese = create(:tag, primary_name: 'temporary_japanese', category: :general)
|
||||
nipponese = create(:tag, primary_name: 'temporary_nipponese', category: :general)
|
||||
# The DB permits this identity; validation has its own contract spec.
|
||||
primary_tag_name_for(japanese, 'ja').update_columns(name: 'shared_name')
|
||||
primary_tag_name_for(nipponese, 'ja').update_columns(name: 'shared_name')
|
||||
english_parent_name = create(:tag_name, name: 'english_parent',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english_parent = create(:tag, primary_tag_name: english_parent_name,
|
||||
category: :material)
|
||||
japanese_parent = create(:tag, primary_name: 'japanese_parent', category: :general)
|
||||
nipponese_parent = create(:tag, primary_name: 'nipponese_parent', category: :general)
|
||||
TagImplication.create!(tag: english, parent_tag: english_parent)
|
||||
TagImplication.create!(tag: japanese, parent_tag: japanese_parent)
|
||||
TagImplication.create!(tag: nipponese, parent_tag: nipponese_parent)
|
||||
|
||||
plan = described_class.new(attributes: { tags: 'shared_name' }).build!(locale)
|
||||
|
||||
@@ -35,22 +35,22 @@ RSpec.describe PostCreatePlan do
|
||||
expect(plan[:post_tag_specs]).to include(
|
||||
{ name: primary_tag_name_for(english_parent, 'en').name, category: :material })
|
||||
expect(plan[:post_tag_specs].pluck(:name))
|
||||
.not_to include(primary_tag_name_for(japanese_parent, 'ja').name)
|
||||
.not_to include(primary_tag_name_for(nipponese_parent, 'ja').name)
|
||||
end
|
||||
|
||||
it 'resolves aliases within the requested language' do
|
||||
japanese = create(:tag, primary_name: 'japanese_canonical')
|
||||
nipponese = create(:tag, primary_name: 'nipponese_canonical')
|
||||
english_name = create(:tag_name, name: 'english_canonical',
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
english = create(:tag, primary_tag_name: english_name, category: :character)
|
||||
japanese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: japanese)
|
||||
nipponese_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: nipponese)
|
||||
english_alias = create(:tag_name, :alias, name: 'shared_alias',
|
||||
tag: english,
|
||||
language_code: 'en', script_code: 'Latn')
|
||||
|
||||
expect(japanese_alias.reload).to have_attributes(
|
||||
tag_id: japanese.id,
|
||||
expect(nipponese_alias.reload).to have_attributes(
|
||||
tag_id: nipponese.id,
|
||||
primary_flg: false, language_code: 'ja')
|
||||
expect(english_alias.reload).to have_attributes(
|
||||
tag_id: english.id,
|
||||
|
||||
@@ -2,15 +2,12 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe TagVersionRecorder do
|
||||
let(:user) { create_member_user! }
|
||||
let(:tag) { create(:tag, primary_name: '日本語名') }
|
||||
let!(:tag) { create(:tag, primary_name: '日本語名') }
|
||||
include_context 'English locale'
|
||||
|
||||
before do
|
||||
Language.insert_all!([{ code: 'en', name: 'English', created_at: Time.current }])
|
||||
Script.insert_all!([{ code: 'Latn', name: 'Latin', created_at: Time.current }])
|
||||
Locale.insert_all!([{ code: 'en', language_code: 'en', script_code: 'Latn',
|
||||
name: 'English', created_at: Time.current }])
|
||||
create(:tag_name, :alias, tag:, name: '別名')
|
||||
create(:tag_name, tag:, language_code: 'en', script_code: 'Latn', name: 'English name')
|
||||
primary_tag_name_for(tag, 'en').update!(name: 'English name', auto_generated: false)
|
||||
create(:tag_name, :alias, tag:, language_code: 'en', script_code: 'Latn',
|
||||
name: 'English alias')
|
||||
end
|
||||
|
||||
@@ -2,12 +2,10 @@ RSpec.shared_context 'English locale' do
|
||||
let!(:locale) do
|
||||
Language.find_or_create_by!(code: 'en') { _1.name = 'English' }
|
||||
Script.find_or_create_by!(code: 'Latn') { _1.name = 'Latin' }
|
||||
unless Locale.exists?(code: 'en')
|
||||
# Reference data only: do not generate names for unrelated existing tags.
|
||||
Locale.insert_all!([
|
||||
{ code: 'en', language_code: 'en', script_code: 'Latn',
|
||||
name: 'English', created_at: Time.current }])
|
||||
Locale.find_or_create_by!(code: 'en') do |record|
|
||||
record.language_code = 'en'
|
||||
record.script_code = 'Latn'
|
||||
record.name = 'English'
|
||||
end
|
||||
Locale.find('en')
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする