mirror of
https://github.com/discourse/discourse.git
synced 2025-05-18 23:43:55 +08:00

This commit adds - `topic_localization` containing its topic, a locale, title, and fancy_title - `post_localization` containing its post, a locale, raw, cooked, the associated post's version - and also APIs to add them Reviewer note: We may ask ourselves "why create separate models instead of one that is generic?" but the different localizable models may be vastly different. For example in posts we only have raw that we need to translate, and topics we have only title, but for categories we have name and description. Then, we may ask ourselves "why not create a polymorphic one that takes in model and column name?" and then we end up with the same thing as what we have currently which is custom fields (which is a mess in itself). Also, when replacing the untranslated content to the translated one, we may find it easier to just `join` + `coalesce` on the dedicated table - it would be a much simpler query than polymorphism.
30 lines
895 B
Ruby
30 lines
895 B
Ruby
# frozen_string_literal: true
|
|
|
|
describe TopicLocalizationDestroyer do
|
|
fab!(:user)
|
|
fab!(:group)
|
|
fab!(:topic)
|
|
fab!(:localization) { Fabricate(:topic_localization, topic:, locale: "ja") }
|
|
|
|
let(:locale) { "ja" }
|
|
|
|
before do
|
|
SiteSetting.experimental_content_localization = true
|
|
SiteSetting.experimental_content_localization_allowed_groups = group.id.to_s
|
|
group.add(user)
|
|
end
|
|
|
|
it "deletes the localization" do
|
|
expect {
|
|
described_class.destroy(topic_id: topic.id, locale: locale, acting_user: user)
|
|
}.to change { TopicLocalization.count }.by(-1)
|
|
expect { TopicLocalization.find(localization.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it "raises not found if the localization is missing" do
|
|
expect {
|
|
described_class.destroy(topic_id: topic.id, locale: "nope", acting_user: user)
|
|
}.to raise_error(Discourse::NotFound)
|
|
end
|
|
end
|