Move by_domain/local interaction check to filter (#39216)
This commit is contained in:
parent
50b6bbe379
commit
8d4f9a97fe
@ -5,9 +5,6 @@ module Admin
|
||||
def index
|
||||
authorize :custom_emoji, :index?
|
||||
|
||||
# If filtering by local emojis, remove by_domain filter.
|
||||
params.delete(:by_domain) if params[:local].present?
|
||||
|
||||
# If filtering by domain, ensure remote filter is set.
|
||||
if params[:by_domain].present?
|
||||
params.delete(:local)
|
||||
|
||||
@ -19,7 +19,7 @@ class CustomEmojiFilter
|
||||
def results
|
||||
scope = CustomEmoji.alphabetic
|
||||
|
||||
params.each do |key, value|
|
||||
relevant_params.each do |key, value|
|
||||
next if IGNORED_PARAMS.include?(key.to_s)
|
||||
|
||||
scope.merge!(scope_for(key, value)) if value.present?
|
||||
@ -30,6 +30,12 @@ class CustomEmojiFilter
|
||||
|
||||
private
|
||||
|
||||
def relevant_params
|
||||
params.tap do |args|
|
||||
args.delete(:by_domain) if args[:local].present?
|
||||
end
|
||||
end
|
||||
|
||||
def scope_for(key, value)
|
||||
case key.to_s
|
||||
when 'local'
|
||||
|
||||
@ -12,9 +12,9 @@ RSpec.describe CustomEmojiFilter do
|
||||
|
||||
context 'when params have values' do
|
||||
context 'when local' do
|
||||
let(:params) { { local: true } }
|
||||
let(:params) { { local: true, by_domain: 'a' } }
|
||||
|
||||
it 'returns ActiveRecord::Relation' do
|
||||
it 'ignores domain and returns ActiveRecord::Relation' do
|
||||
expect(subject).to be_a(ActiveRecord::Relation)
|
||||
expect(subject).to contain_exactly(custom_emoji_domain_nil)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user