mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Rely on pluck
for the SELECT in RuleTranslation.languages
(#35826)
This commit is contained in:
parent
abe5413638
commit
20bc34ca52
|
@ -22,6 +22,6 @@ class RuleTranslation < ApplicationRecord
|
|||
scope :by_language_length, -> { order(Arel.sql('LENGTH(LANGUAGE)').desc) }
|
||||
|
||||
def self.languages
|
||||
RuleTranslation.joins(:rule).merge(Rule.kept).select(:language).distinct.pluck(:language).sort
|
||||
joins(:rule).merge(Rule.kept).distinct.pluck(:language).sort
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,4 +52,22 @@ RSpec.describe RuleTranslation do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.languages' do
|
||||
let(:discarded_rule) { Fabricate :rule, deleted_at: 5.days.ago }
|
||||
let(:kept_rule) { Fabricate :rule }
|
||||
|
||||
before do
|
||||
Fabricate :rule_translation, rule: discarded_rule, language: 'en'
|
||||
Fabricate :rule_translation, rule: kept_rule, language: 'es'
|
||||
Fabricate :rule_translation, language: 'fr'
|
||||
Fabricate :rule_translation, language: 'es'
|
||||
end
|
||||
|
||||
it 'returns ordered distinct languages connected to non-discarded rules' do
|
||||
expect(described_class.languages)
|
||||
.to be_an(Array)
|
||||
.and eq(%w(es fr))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user