Sha256: 0fcc8f05699ffc356fe5cee8b0b36d60c2ca8d6c23023d922927917b98b7af84

Contents?: true

Size: 1.17 KB

Versions: 27

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

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

27 entries across 27 versions & 1 rubygems

Version Path
mongoid-8.1.9 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.9 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.8 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.7 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.6 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.8 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.5 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.4 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.7 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.3 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.2 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.6 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.5.4 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.1 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.5 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.1.0 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.5.3 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.4 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-8.0.3 spec/mongoid/criteria/queryable/expandable_spec.rb
mongoid-7.5.2 spec/mongoid/criteria/queryable/expandable_spec.rb