mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-30 23:05:35 +08:00
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" />
49 lines
1.5 KiB
Ruby
49 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe PostLocalizationUpdater do
|
|
fab!(:user)
|
|
fab!(:post) { Fabricate(:post, version: 99) }
|
|
fab!(:group)
|
|
fab!(:post_localization) do
|
|
Fabricate(:post_localization, post: post, locale: "ja", raw: "古いバージョン")
|
|
end
|
|
|
|
let(:locale) { "ja" }
|
|
let(:new_raw) { "新しいバージョンです" }
|
|
|
|
before do
|
|
SiteSetting.content_localization_enabled = true
|
|
SiteSetting.content_localization_allowed_groups = group.id.to_s
|
|
group.add(user)
|
|
end
|
|
|
|
it "updates an existing localization" do
|
|
localization =
|
|
described_class.update(post_id: post.id, locale: locale, raw: new_raw, user: user)
|
|
|
|
expect(localization).to have_attributes(
|
|
raw: new_raw,
|
|
cooked: PrettyText.cook(new_raw),
|
|
localizer_user_id: user.id,
|
|
post_version: post.version,
|
|
)
|
|
end
|
|
|
|
it "enqueues ProcessLocalizedCook job" do
|
|
loc = described_class.update(post_id: post.id, locale: locale, raw: new_raw, user: user)
|
|
|
|
expect_job_enqueued(job: :process_localized_cooked, args: { post_localization_id: loc.id })
|
|
end
|
|
|
|
it "raises not found if the localization is missing" do
|
|
expect {
|
|
described_class.update(post_id: post.id, locale: "nope", raw: new_raw, user: user)
|
|
}.to raise_error(Discourse::NotFound)
|
|
end
|
|
|
|
it "raises not found if the post is missing" do
|
|
expect {
|
|
described_class.update(post_id: -1, locale: locale, raw: new_raw, user: user)
|
|
}.to raise_error(Discourse::NotFound)
|
|
end
|
|
end
|