Sha256: 9e02143f09b6c35f99c7b5c1e00fef08f2dc1b1483ffffd47bc554b3e9131b84

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Mongoid::Criteria::Queryable::Expandable do

  let(:query) do
    Mongoid::Query.new
  end

  describe '#expand_condition_to_array_values' do
    shared_examples_for 'expands' do

      it 'expands' do
        query.send(:expand_condition_to_array_values, criterion).should == expected
      end

      context 'when input is frozen' do
        before do
          criterion.freeze
        end

        it 'expands' do
          query.send(:expand_condition_to_array_values, criterion).should == expected
        end
      end

      it 'does not modify input' do
        criterion_copy = criterion.dup.freeze

        query.send(:expand_condition_to_array_values, criterion).should == expected

        expect(criterion).to eq(criterion_copy)
      end
    end

    context 'literal value' do
      let(:criterion) do
        {foo: 4}
      end

      let(:expected) do
        {foo: [4]}
      end

      it_behaves_like 'expands'
    end

    context 'Range value' do
      let(:criterion) do
        {foo: 1..4}
      end

      let(:expected) do
        {foo: [1, 2, 3, 4]}
      end

      it_behaves_like 'expands'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongoid-7.3.5 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.3.4 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.3.3 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.3.2 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.3.1 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.3.0 spec/mongoid/criteria/queryable/expandable_spec.rb