Skip to content

Scopes combined with :or does not work #1110

@runephilosof

Description

@runephilosof

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions