このコミットが含まれているのは:
@@ -95,7 +95,8 @@ RSpec.describe PostCreator do
|
||||
post = described_class.new(actor:, attributes:).create!(locale)
|
||||
|
||||
expect(Tag).to have_received(:find_or_create_by_tag_name!)
|
||||
.with(locale, 'locale_character', category: :character).at_least(:once)
|
||||
.with(locale, 'locale_character', category: :character,
|
||||
created_by_user: actor).at_least(:once)
|
||||
tag_name = TagName.find_by!(language_code: 'ain', name: 'locale_character')
|
||||
expect(tag_name).to have_attributes(script_code: 'Kana', primary_flg: true)
|
||||
expect(post.tags).to include(tag_name.tag)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TagNameCompletion do
|
||||
let(:author) { create(:user, :member) }
|
||||
let!(:language) { Language.create!(code: 'ain', name: 'ain') }
|
||||
let!(:script) { Script.create!(code: 'Kana', name: 'Kana') }
|
||||
let(:locale) do
|
||||
@@ -65,4 +66,62 @@ RSpec.describe TagNameCompletion do
|
||||
.to contain_exactly(['ja', 'アイヌ'], ['ain', 'アイヌ'])
|
||||
expect(Tag.find_or_create_by_tag_name!(locale, 'アイヌ', category: :general)).to eq(tag)
|
||||
end
|
||||
|
||||
['ja', 'ain'].each do |language|
|
||||
it "records one authored create with all names for a #{ language } origin" do
|
||||
ainu_locale = locale
|
||||
origin = language == 'ja' ? Locale.nipponese : ainu_locale
|
||||
tag = nil
|
||||
|
||||
expect {
|
||||
tag = Tag.find_or_create_by_tag_name!(origin, 'アイヌ', category: :general,
|
||||
created_by_user: author)
|
||||
}.to change(TagVersion, :count).by(1)
|
||||
|
||||
version = tag.tag_versions.sole
|
||||
expect(version).to have_attributes(
|
||||
event_type: 'create', version_no: 1, created_by_user_id: author.id)
|
||||
expect(tag.reload.version_no).to eq(1)
|
||||
expect(version.names).to eq(
|
||||
'ja' => { 'name' => 'アイヌ', 'script_code' => 'Jpan',
|
||||
'auto_generated' => language != 'ja', 'aliases' => [] },
|
||||
'ain' => { 'name' => 'アイヌ', 'script_code' => 'Kana',
|
||||
'auto_generated' => language != 'ain', 'aliases' => [] })
|
||||
|
||||
expect {
|
||||
described_class.for_tag!(tag, created_by_user: author)
|
||||
found = Tag.find_or_create_by_tag_name!(origin, 'アイヌ', category: :general,
|
||||
created_by_user: author)
|
||||
expect(found).to eq(tag)
|
||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: author)
|
||||
}.not_to change(TagVersion, :count)
|
||||
expect(version.reload.created_by_user_id).to eq(author.id)
|
||||
end
|
||||
end
|
||||
|
||||
it 'records the author even when no additional language needs completion' do
|
||||
tag = build(:tag, primary_name: 'single_language_creation')
|
||||
|
||||
described_class.for_tag!(tag, created_by_user: author)
|
||||
|
||||
expect(tag).to be_persisted
|
||||
expect(tag.tag_versions.sole).to have_attributes(
|
||||
event_type: 'create', version_no: 1, created_by_user_id: author.id)
|
||||
expect(tag.tag_versions.sole.names.keys).to eq(['ja'])
|
||||
end
|
||||
|
||||
it 'rolls back a new tag and all names when its create history fails' do
|
||||
locale
|
||||
author
|
||||
before_counts = [Tag.count, TagName.count, TagVersion.count]
|
||||
allow(TagVersioning).to receive(:record!).and_raise('history failed')
|
||||
|
||||
expect {
|
||||
Tag.find_or_create_by_tag_name!(Locale.nipponese, 'atomic_new_history',
|
||||
category: :general, created_by_user: author)
|
||||
}.to raise_error('history failed')
|
||||
|
||||
expect([Tag.count, TagName.count, TagVersion.count]).to eq(before_counts)
|
||||
expect(TagName.where(name: 'atomic_new_history')).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする