Skip to content

Commit

Permalink
fix is_blank and is_present filters for uuid columns (#3629)
Browse files Browse the repository at this point in the history
* fix is_blank and is_present filters for uuid columns

* fix rubocop errors
  • Loading branch information
ozenbusra authored Jun 17, 2023
1 parent 923d73e commit 647347c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def unary_operators
case @type
when :boolean
boolean_unary_operators
when :uuid
uuid_unary_operators
when :integer, :decimal, :float
numeric_unary_operators
else
Expand Down Expand Up @@ -230,6 +232,7 @@ def boolean_unary_operators
)
end
alias_method :numeric_unary_operators, :boolean_unary_operators
alias_method :uuid_unary_operators, :boolean_unary_operators

def range_filter(min, max)
if min && max && min == max
Expand Down
44 changes: 41 additions & 3 deletions spec/rails_admin/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,47 @@ def build_statement(type, value, operator)
end
end

it 'supports uuid type query' do
uuid = SecureRandom.uuid
expect(build_statement(:uuid, uuid, nil)).to eq(['(field = ?)', uuid])
describe 'uuid type queries' do
it 'supports uuid type query' do
uuid = SecureRandom.uuid
expect(build_statement(:uuid, uuid, nil)).to eq(['(field = ?)', uuid])
end

it "supports '_blank' operator" do
[['_blank', ''], ['', '_blank']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
end
end

it "supports '_present' operator" do
[['_present', ''], ['', '_present']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
end
end

it "supports '_null' operator" do
[['_null', ''], ['', '_null']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
end
end

it "supports '_not_null' operator" do
[['_not_null', ''], ['', '_not_null']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
end
end

it "supports '_empty' operator" do
[['_empty', ''], ['', '_empty']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NULL)'])
end
end

it "supports '_not_empty' operator" do
[['_not_empty', ''], ['', '_not_empty']].each do |value, operator|
expect(build_statement(:uuid, value, operator)).to eq(['(field IS NOT NULL)'])
end
end
end
end

Expand Down

0 comments on commit 647347c

Please sign in to comment.