Skip to content

Commit 647347c

Browse files
authored
fix is_blank and is_present filters for uuid columns (#3629)
* fix is_blank and is_present filters for uuid columns * fix rubocop errors
1 parent 923d73e commit 647347c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

lib/rails_admin/adapters/active_record.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def unary_operators
201201
case @type
202202
when :boolean
203203
boolean_unary_operators
204+
when :uuid
205+
uuid_unary_operators
204206
when :integer, :decimal, :float
205207
numeric_unary_operators
206208
else
@@ -230,6 +232,7 @@ def boolean_unary_operators
230232
)
231233
end
232234
alias_method :numeric_unary_operators, :boolean_unary_operators
235+
alias_method :uuid_unary_operators, :boolean_unary_operators
233236

234237
def range_filter(min, max)
235238
if min && max && min == max

spec/rails_admin/adapters/active_record_spec.rb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,47 @@ def build_statement(type, value, operator)
575575
end
576576
end
577577

578-
it 'supports uuid type query' do
579-
uuid = SecureRandom.uuid
580-
expect(build_statement(:uuid, uuid, nil)).to eq(['(field = ?)', uuid])
578+
describe 'uuid type queries' do
579+
it 'supports uuid type query' do
580+
uuid = SecureRandom.uuid
581+
expect(build_statement(:uuid, uuid, nil)).to eq(['(field = ?)', uuid])
582+
end
583+
584+
it "supports '_blank' operator" do
585+
[['_blank', ''], ['', '_blank']].each do |value, operator|
586+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
587+
end
588+
end
589+
590+
it "supports '_present' operator" do
591+
[['_present', ''], ['', '_present']].each do |value, operator|
592+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
593+
end
594+
end
595+
596+
it "supports '_null' operator" do
597+
[['_null', ''], ['', '_null']].each do |value, operator|
598+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
599+
end
600+
end
601+
602+
it "supports '_not_null' operator" do
603+
[['_not_null', ''], ['', '_not_null']].each do |value, operator|
604+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
605+
end
606+
end
607+
608+
it "supports '_empty' operator" do
609+
[['_empty', ''], ['', '_empty']].each do |value, operator|
610+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
611+
end
612+
end
613+
614+
it "supports '_not_empty' operator" do
615+
[['_not_empty', ''], ['', '_not_empty']].each do |value, operator|
616+
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
617+
end
618+
end
581619
end
582620
end
583621

0 commit comments

Comments
 (0)