多言語化の基盤作り (#55) (#421)

Reviewed-on: #421
Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #421 でマージされました。
このコミットが含まれているのは:
2026-10-03 02:00:09 +09:00
committed by みてるぞ
コミット e6ab941774
91個のファイルの変更、3370行の追加、1223行の削除
+33 -1
ファイルの表示
@@ -1,7 +1,10 @@
require 'rails_helper'
RSpec.describe PostBulkCreator do
include_context 'English locale'
it 'limits workers to two and keeps failures in their request slots' do
locale = Locale.nipponese
actor = instance_double(User, id: 123)
allow(User).to receive(:find).with(123) {
instance_double(User, id: 123)
@@ -9,6 +12,7 @@ RSpec.describe PostBulkCreator do
mutex = Mutex.new
active = 0
maximum_active = 0
creators = []
allow(PostCreatePreflight).to receive(:new) do |attributes:, **|
preflight = instance_double(PostCreatePreflight)
@@ -28,6 +32,7 @@ RSpec.describe PostBulkCreator do
end
allow(PostCreator).to receive(:new) do |attributes:, **|
creator = instance_double(PostCreator)
mutex.synchronize { creators << creator }
if attributes[:title] == 'broken'
allow(creator).to receive(:create!).and_raise(StandardError, 'broken')
else
@@ -45,7 +50,12 @@ RSpec.describe PostBulkCreator do
results = described_class.new(
actor:,
posts:,
thumbnails: { }).run.fetch(:results)
thumbnails: { }).run(locale).fetch(:results)
expect(creators.length).to eq(posts.length)
creators.each do |creator|
expect(creator).to have_received(:create!).with(locale).once
end
expect(maximum_active).to eq(2)
expect(results.length).to eq(posts.length)
@@ -56,4 +66,26 @@ RSpec.describe PostBulkCreator do
expect(results[2].dig(:post, :id)).to eq(3)
expect(results[3].dig(:post, :id)).to eq(4)
end
it 'passes a future English locale to preflight and creation in every worker' do
pending '日本語以外の Locale 有効化は別課題で実装する'
locale
actor = instance_double(User, id: 123)
allow(User).to receive(:find).with(123).and_return(actor)
preflight = instance_double(PostCreatePreflight)
creator = instance_double(PostCreator)
post = instance_double(Post, id: 1)
allow(PostCreatePreflight).to receive(:new).and_return(preflight)
allow(preflight).to receive(:run).with(locale).and_return(existing_post_id: nil)
allow(PostCreator).to receive(:new).and_return(creator)
allow(creator).to receive(:create!).with(locale).and_return(post)
results = described_class.new(
actor:, posts: [{ title: 'future post' }], thumbnails: { }).run(locale)
expect(results.fetch(:results)).to contain_exactly(
hash_including(status: 'created', post: { id: 1 }))
expect(preflight).to have_received(:run).with(locale).once
expect(creator).to have_received(:create!).with(locale).once
end
end