discourse/spec/lib/post_localization_creator_spec.rb
Natalie Tay 38e6420016
FEATURE: Also process manually updated translations (#35276)
This is a follow up to
https://github.com/discourse/discourse/pull/34900.

When a user manually updates translation via the translation composer,
also send the new translated cooked for post processing. I moved the
Processor to core, given PostLocalizations are core feature.

<img width="551" height="385" alt="Screenshot 2025-10-08 at 6 12 26 PM"
src="https://github.com/user-attachments/assets/1cce7ce3-5487-4e75-90fd-440792b9a899"
/>
2025-10-09 00:33:36 +08:00

40 lines
1 KiB
Ruby

# frozen_string_literal: true
describe PostLocalizationCreator do
fab!(:user)
fab!(:post)
fab!(:group)
let(:locale) { "ja" }
let(:raw) { "これは翻訳です。" }
before do
SiteSetting.content_localization_enabled = true
SiteSetting.content_localization_allowed_groups = group.id.to_s
group.add(user)
end
it "creates a post localization record" do
localization = described_class.create(post_id: post.id, locale:, raw:, user:)
expect(PostLocalization.find(localization.id)).to have_attributes(
post_id: post.id,
locale:,
raw:,
localizer_user_id: user.id,
cooked: PrettyText.cook(raw),
)
end
it "enqueues ProcessLocalizedCook job" do
loc = described_class.create(post_id: post.id, locale:, raw:, user:)
expect_job_enqueued(job: :process_localized_cooked, args: { post_localization_id: loc.id })
end
it "raises not found if the post is missing" do
expect { described_class.create(post_id: -1, locale:, raw:, user:) }.to raise_error(
Discourse::NotFound,
)
end
end