mirror of
https://github.com/mastodon/mastodon.git
synced 2025-07-11 15:03:15 +00:00
56 lines
1.6 KiB
Ruby
56 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe RuleTranslation do
|
|
describe 'Associations' do
|
|
it { is_expected.to belong_to(:rule) }
|
|
end
|
|
|
|
describe 'Validations' do
|
|
subject { Fabricate.build :rule_translation }
|
|
|
|
it { is_expected.to validate_presence_of(:language) }
|
|
it { is_expected.to validate_presence_of(:text) }
|
|
it { is_expected.to validate_length_of(:text).is_at_most(Rule::TEXT_SIZE_LIMIT) }
|
|
it { is_expected.to validate_uniqueness_of(:language).scoped_to(:rule_id) }
|
|
end
|
|
|
|
describe 'Scopes' do
|
|
describe '.for_locale' do
|
|
let!(:matching) { Fabricate :rule_translation, language: 'en' }
|
|
let!(:missing) { Fabricate :rule_translation, language: 'es' }
|
|
|
|
context 'when sent top-level string' do
|
|
it 'includes expected records' do
|
|
results = described_class.for_locale('en')
|
|
|
|
expect(results)
|
|
.to include(matching)
|
|
.and not_include(missing)
|
|
end
|
|
end
|
|
|
|
context 'when sent sub string' do
|
|
it 'includes expected records' do
|
|
results = described_class.for_locale('en-US')
|
|
|
|
expect(results)
|
|
.to include(matching)
|
|
.and not_include(missing)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '.by_language_length' do
|
|
let!(:top_level) { Fabricate :rule_translation, language: 'en' }
|
|
let!(:sub_level) { Fabricate :rule_translation, language: 'en-US' }
|
|
|
|
it 'returns results ordered by length' do
|
|
expect(described_class.by_language_length)
|
|
.to eq([sub_level, top_level])
|
|
end
|
|
end
|
|
end
|
|
end
|