Sha256: 4058fbb4fa299c0536c17fbc079ed25caf778468410795e4778c6b462fe99a5e

Contents?: true

Size: 1.8 KB

Versions: 22

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

module Ransack
  module Nodes
    describe Condition do

      context 'with an alias' do
        subject {
          Condition.extract(
            Context.for(Person), 'term_start', Person.first(2).map(&:name)
          )
        }

        specify { expect(subject.combinator).to eq 'or' }
        specify { expect(subject.predicate.name).to eq 'start' }

        it 'converts the alias to the correct attributes' do
          expect(subject.attributes.map(&:name)).to eq(['name', 'email'])
        end
      end

      context 'with multiple values and an _any predicate' do
        subject {
          Condition.extract(
            Context.for(Person), 'name_eq_any', Person.first(2).map(&:name)
          )
        }

        specify { expect(subject.values.size).to eq(2) }
      end

      describe '#negative?' do
        let(:context) { Context.for(Person) }
        let(:eq)      { Condition.extract(context, 'name_eq', 'A') }
        let(:not_eq)  { Condition.extract(context, 'name_not_eq', 'A') }

        specify { expect(not_eq.negative?).to be true }
        specify { expect(eq.negative?).to be false }
      end

      context 'with an invalid predicate' do
        subject {
          Condition.extract(
            Context.for(Person), 'name_invalid', Person.first.name
          )
        }

        context "when ignore_unknown_conditions is false" do
          before do
            Ransack.configure { |c| c.ignore_unknown_conditions = false }
          end

          specify { expect { subject }.to raise_error ArgumentError }
        end

        context "when ignore_unknown_conditions is true" do
          before do
            Ransack.configure { |c| c.ignore_unknown_conditions = true }
          end

          specify { expect(subject).to be_nil }
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/spec/ransack/nodes/condition_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/ransack-2.4.2/spec/ransack/nodes/condition_spec.rb
ransack-2.4.2 spec/ransack/nodes/condition_spec.rb
ransack-2.4.1 spec/ransack/nodes/condition_spec.rb
ransack-2.4.0 spec/ransack/nodes/condition_spec.rb
ransack-2.3.2 spec/ransack/nodes/condition_spec.rb
ransack-2.3.1 spec/ransack/nodes/condition_spec.rb
ransack-2.3.0 spec/ransack/nodes/condition_spec.rb
ransack-1.8.10 spec/ransack/nodes/condition_spec.rb
ransack-2.1.1 spec/ransack/nodes/condition_spec.rb
ransack-2.1.0 spec/ransack/nodes/condition_spec.rb
ransack-2.0.1 spec/ransack/nodes/condition_spec.rb
ransack-2.0.0 spec/ransack/nodes/condition_spec.rb
ransack-1.8.9 spec/ransack/nodes/condition_spec.rb
ransack-1.8.8 spec/ransack/nodes/condition_spec.rb
ransack-1.8.7 spec/ransack/nodes/condition_spec.rb
ransack-1.8.6 spec/ransack/nodes/condition_spec.rb
ransack-1.8.4 spec/ransack/nodes/condition_spec.rb
ransack-1.8.3 spec/ransack/nodes/condition_spec.rb
ransack-1.8.2 spec/ransack/nodes/condition_spec.rb