mirror of
https://github.com/mastodon/mastodon.git
synced 2025-06-18 02:59:15 +00:00

Some checks are pending
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
51 lines
2.0 KiB
Ruby
51 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Rule do
|
|
describe 'scopes' do
|
|
describe 'ordered' do
|
|
let(:deleted_rule) { Fabricate(:rule, deleted_at: 10.days.ago) }
|
|
let(:first_rule) { Fabricate(:rule, deleted_at: nil, priority: 1) }
|
|
let(:last_rule) { Fabricate(:rule, deleted_at: nil, priority: 10) }
|
|
|
|
it 'finds the correct records' do
|
|
results = described_class.ordered
|
|
|
|
expect(results).to eq([first_rule, last_rule])
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#move!' do
|
|
let!(:first_rule) { Fabricate(:rule, text: 'foo') }
|
|
let!(:second_rule) { Fabricate(:rule, text: 'bar') }
|
|
let!(:third_rule) { Fabricate(:rule, text: 'baz') }
|
|
|
|
it 'moves the rules as expected' do
|
|
expect { first_rule.move!(+1) }
|
|
.to change { described_class.ordered.pluck(:text) }.from(%w(foo bar baz)).to(%w(bar foo baz))
|
|
|
|
expect { first_rule.move!(-1) }
|
|
.to change { described_class.ordered.pluck(:text) }.from(%w(bar foo baz)).to(%w(foo bar baz))
|
|
|
|
expect { third_rule.move!(-1) }
|
|
.to change { described_class.ordered.pluck(:text) }.from(%w(foo bar baz)).to(%w(foo baz bar))
|
|
|
|
expect { second_rule.move!(-1) }
|
|
.to change { described_class.ordered.pluck(:text) }.from(%w(foo baz bar)).to(%w(foo bar baz))
|
|
end
|
|
end
|
|
|
|
describe '#translation_for' do
|
|
let!(:rule) { Fabricate(:rule, text: 'This is a rule', hint: 'This is an explanation of the rule') }
|
|
let!(:translation) { Fabricate(:rule_translation, rule: rule, text: 'Ceci est une règle', hint: 'Ceci est une explication de la règle', language: 'fr') }
|
|
|
|
it 'returns the expected translation, including fallbacks' do
|
|
expect(rule.translation_for(:en)).to have_attributes(text: rule.text, hint: rule.hint)
|
|
expect(rule.translation_for(:fr)).to have_attributes(text: translation.text, hint: translation.hint)
|
|
expect(rule.translation_for(:'fr-CA')).to have_attributes(text: translation.text, hint: translation.hint)
|
|
end
|
|
end
|
|
end
|