mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 11:09:34 +08:00
WIP: extract outdated/up-to-date logic in model
This commit is contained in:
parent
53210841c8
commit
ebde13a527
|
@ -135,14 +135,7 @@ class Admin::SiteTextsController < Admin::AdminController
|
||||||
|
|
||||||
raise Discourse::NotFound if override.blank?
|
raise Discourse::NotFound if override.blank?
|
||||||
|
|
||||||
if override.outdated?
|
if override.make_up_to_date!
|
||||||
override.update!(
|
|
||||||
status: "up_to_date",
|
|
||||||
original_translation:
|
|
||||||
I18n.overrides_disabled do
|
|
||||||
I18n.t(TranslationOverride.transform_pluralized_key(params[:id]), locale: :en)
|
|
||||||
end,
|
|
||||||
)
|
|
||||||
render json: success_json
|
render json: success_json
|
||||||
else
|
else
|
||||||
render json: failed_json.merge(message: "Can only dismiss outdated translations"), status: 422
|
render json: failed_json.merge(message: "Can only dismiss outdated translations"), status: 422
|
||||||
|
|
|
@ -170,6 +170,12 @@ class TranslationOverride < ActiveRecord::Base
|
||||||
translation_key.to_s.end_with?("_MF")
|
translation_key.to_s.end_with?("_MF")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_up_to_date!
|
||||||
|
return unless outdated?
|
||||||
|
self.original_translation = current_default
|
||||||
|
update_attribute!(:status, :up_to_date)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def transformed_key
|
def transformed_key
|
||||||
|
|
|
@ -382,4 +382,36 @@ RSpec.describe TranslationOverride do
|
||||||
it { is_expected.not_to be_a_message_format }
|
it { is_expected.not_to be_a_message_format }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#make_up_to_date!" do
|
||||||
|
fab!(:override) { Fabricate(:translation_override, translation_key: "js.posts_likes_MF") }
|
||||||
|
|
||||||
|
context "when override is not outdated" do
|
||||||
|
it "does nothing" do
|
||||||
|
expect { override.make_up_to_date! }.not_to change { override.reload.attributes }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a falsy value" do
|
||||||
|
expect(override.make_up_to_date!).to be_falsy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when override is outdated" do
|
||||||
|
before { override.update_columns(status: :outdated, value: "{ Invalid MF syntax") }
|
||||||
|
|
||||||
|
it "updates its original translation to match the current default" do
|
||||||
|
expect { override.make_up_to_date! }.to change { override.reload.original_translation }.to(
|
||||||
|
I18n.t("js.posts_likes_MF"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sets its status to 'up_to_date'" do
|
||||||
|
expect { override.make_up_to_date! }.to change { override.reload.up_to_date? }.to(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a truthy value" do
|
||||||
|
expect(override.make_up_to_date!).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user