Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/graphiti/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ def filter_not_eq(scope, attribute, value)
alias_method :filter_enum_not_eql, :filter_not_eq

def filter_string_eq(scope, attribute, value, is_not: false)
return filter_string_eql(scope, attribute, nil, is_not: is_not) if Array(value).compact.blank?

column = column_for(scope, attribute)
clause = column.lower.eq_any(value.map(&:downcase))
clause = column.lower.eq_any(value.map { |val| val.downcase })
is_not ? scope.where.not(clause) : scope.where(clause)
end

def filter_string_eql(scope, attribute, value, is_not: false)
clause = {attribute => value}
clause = {attribute => value.presence}
is_not ? scope.where.not(clause) : scope.where(clause)
end

def filter_string_not_eq(scope, attribute, value)
filter_string_eq(scope, attribute, value, is_not: true)
filter_string_eq(scope, attribute, value.presence, is_not: true)
end

def filter_string_not_eql(scope, attribute, value)
filter_string_eql(scope, attribute, value, is_not: true)
filter_string_eql(scope, attribute, value.presence, is_not: true)
end

# Arel has different match escaping behavior before rails 5.
Expand Down
36 changes: 36 additions & 0 deletions spec/integration/rails/finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ def resource
it "executes case-insensitive search" do
expect(ids).to eq([author2.id, author3.id])
end

context "with nil value" do
let(:value) { nil }
let!(:author3) { Legacy::Author.create! }

it "works" do
expect(ids).to eq([author3.id])
end
end
end

context "nothing" do
Expand All @@ -297,6 +306,15 @@ def resource
it "executes case-sensitive search" do
expect(ids).to eq([author3.id])
end

context "with nil value" do
let(:value) { nil }
let!(:author3) { Legacy::Author.create! }

it "works" do
expect(ids).to eq([author3.id])
end
end
end

context "!eq" do
Expand All @@ -305,6 +323,15 @@ def resource
it "executes case-insensitive NOT search" do
expect(ids).to eq([author1.id])
end

context "with nil value" do
let(:value) { {'!eq': nil} }
let!(:author3) { Legacy::Author.create! }

it "works" do
expect(ids).to eq([author1.id, author2.id])
end
end
end

# test not_ alternative to !
Expand All @@ -314,6 +341,15 @@ def resource
it "executes case-insensitive NOT search" do
expect(ids).to eq([author1.id])
end

context "with nil value" do
let(:value) { {not_eq: nil} }
let!(:author3) { Legacy::Author.create! }

it "works" do
expect(ids).to eq([author1.id, author2.id])
end
end
end

# test not_ alternative to !
Expand Down
1 change: 1 addition & 0 deletions spec/tmp/local_secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
85b70ecb76ac772627f629a92a3b6f480e5ef6f12d4ba704656d87a8e9c2c2bad3155ea4fab11f4837d94dba3436c9c31bd9468f0603a4c9f0aa28641ac6a5d5
Loading