Add ability to reorder server rules from admin interface (#34737)

This commit is contained in:
Claire 2025-05-20 14:49:11 +02:00 committed by GitHub
parent 8ed0408adb
commit d7cb6068b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 97 additions and 2 deletions

View file

@ -16,4 +16,24 @@ RSpec.describe Rule do
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
end

View file

@ -48,6 +48,29 @@ RSpec.describe 'Admin Rules' do
end
end
describe 'Moving down an existing rule' do
let!(:first_rule) { Fabricate(:rule, text: 'This is another rule') }
let!(:second_rule) { Fabricate(:rule, text: 'This is a rule') }
it 'moves the rule down' do
visit admin_rules_path
expect(page)
.to have_content(I18n.t('admin.rules.title'))
expect(Rule.ordered.pluck(:text)).to eq ['This is another rule', 'This is a rule']
click_on(I18n.t('admin.rules.move_down'))
expect(page)
.to have_content(I18n.t('admin.rules.title'))
.and have_content(first_rule.text)
.and have_content(second_rule.text)
expect(Rule.ordered.pluck(:text)).to eq ['This is a rule', 'This is another rule']
end
end
describe 'Editing an existing rule' do
let!(:rule) { Fabricate :rule, text: 'Rule text' }