mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Merge 16d62b0cb4
into de09e33c92
This commit is contained in:
commit
c1e00944a9
|
@ -3,6 +3,7 @@
|
|||
module Admin
|
||||
class RulesController < BaseController
|
||||
before_action :set_rule, except: [:index, :new, :create]
|
||||
before_action :build_missing_translations, only: :edit
|
||||
|
||||
def index
|
||||
authorize :rule, :index?
|
||||
|
@ -17,9 +18,6 @@ module Admin
|
|||
|
||||
def edit
|
||||
authorize @rule, :update?
|
||||
|
||||
missing_languages = RuleTranslation.languages - @rule.translations.pluck(:language)
|
||||
missing_languages.each { |lang| @rule.translations.build(language: lang) }
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -78,5 +76,9 @@ module Admin
|
|||
params
|
||||
.expect(rule: [:text, :hint, :priority, translations_attributes: [[:id, :language, :text, :hint, :_destroy]]])
|
||||
end
|
||||
|
||||
def build_missing_translations
|
||||
@rule.untranslated_languages.each { |language| @rule.translations.build(language:) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,4 +44,8 @@ class Rule < ApplicationRecord
|
|||
@cached_translations ||= {}
|
||||
@cached_translations[locale] ||= translations.for_locale(locale).by_language_length.first || translations.build(language: locale, text: text, hint: hint)
|
||||
end
|
||||
|
||||
def untranslated_languages
|
||||
RuleTranslation.excluding(translations).languages
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,4 +47,28 @@ RSpec.describe Rule do
|
|||
expect(rule.translation_for(:'fr-CA')).to have_attributes(text: translation.text, hint: translation.hint)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#untranslated_languages' do
|
||||
subject { rule.untranslated_languages }
|
||||
|
||||
let(:rule) { Fabricate :rule }
|
||||
|
||||
context 'when there are no translations' do
|
||||
it { is_expected.to be_an(Array).and(be_empty) }
|
||||
end
|
||||
|
||||
context 'when there are translations' do
|
||||
let(:linked_to_rule_translation) { Fabricate :rule_translation, language: 'es', rule: }
|
||||
let!(:missing_translation) { Fabricate :rule_translation, language: 'fr' }
|
||||
let!(:discarded_rule_translation) { Fabricate :rule_translation, language: 'gb', rule: discarded_rule }
|
||||
let(:discarded_rule) { Fabricate :rule, deleted_at: 5.days.ago }
|
||||
|
||||
it 'returns language strings of missing translations' do
|
||||
expect(subject)
|
||||
.to include(missing_translation.language)
|
||||
.and not_include(linked_to_rule_translation.language)
|
||||
.and not_include(discarded_rule_translation.language)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user