ransack
ransack copied to clipboard
Scopes combined with :or does not work
As demonstrated in https://github.com/runephilosof/ransack-scopes-or The combinator :or does not work with scopes.
class Test < ActiveRecord::Base
scope :red, -> { where(color: :red) }
scope :green, -> { where(color: :green) }
def self.ransackable_scopes(a = nil)
[:red, :green]
end
end
RSpec.describe Test do
context "when conditions are two scopes" do
let(:ransack) { Test.ransack(red: true, green: true, m: :or) }
it "supports :or combinator" do
expect(ransack.base.combinator).to eq :or # Success
end
it "generates SQL containing OR" do
expect(ransack.result.to_sql).to include "OR" # Failure
end
end
context "when conditions are a scope and an attribute" do
let(:ransack) { Test.ransack(red: true, color_cont: "green", m: :or) }
it "supports :or combinator" do
expect(ransack.base.combinator).to eq :or # Success
end
it "generates SQL containing OR" do
expect(ransack.result.to_sql).to include "OR" # Failure
end
end
end
Just hit the same issue. Search with ransackable_scopes
applies AND
after the scope part of the query instead of OR
even if m: 'or'
is set.
Any news about this issue?