Skip to content

Scopes combined with :or does not work #1110

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions