Skip to content

Commit e536cf8

Browse files
Fix NameError raised with empty dynamic fields (#350)
1 parent f86aa24 commit e536cf8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/datagrid/drivers/active_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def builtin_type(scope, field)
9494
scope.connection.select_all(
9595
scope.unscope(:select, :order).select(field => "custom_field").limit(0).arel
9696
).column_types['custom_field']&.type
97-
rescue ActiveRecord::StatementInvalid
97+
rescue ::ActiveRecord::StatementInvalid
9898
nil
9999
end
100100
end

spec/datagrid/drivers/active_record_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
end
3939
end
4040

41+
describe "when providing blank dynamic fields with include_blank" do
42+
subject do
43+
test_grid(name: entry.name, condition1: { field: "", operator: "eq", value: "test" }) do
44+
scope { Entry }
45+
46+
filter(:name)
47+
filter(
48+
:condition1, :dynamic,
49+
operators: %w[eq not_eq], include_blank: true, select: %w[name category access_level],
50+
)
51+
end.assets
52+
end
53+
54+
let(:entry) { Entry.create!(name: "test") }
55+
56+
it "still applies other filters without raising errors" do
57+
expect(subject).to eq([entry])
58+
end
59+
end
60+
4161
describe "where by timestamp" do
4262
subject do
4363
test_grid(created_at: 10.days.ago..5.days.ago) do

0 commit comments

Comments
 (0)