Sha256: c5722f32b55303d29f1b96c29ba17437c5c433bc8060c7ea9c1ca7183098df41

Contents?: true

Size: 1.56 KB

Versions: 24

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"


describe Mongoid::Criteria::Queryable::Extensions::Regexp do

  describe ".evolve" do

    context "when provided a regexp" do

      let(:regexp) do
        /\A[123]/
      end

      let(:evolved) do
        Regexp.evolve(regexp)
      end

      it "returns the regexp" do
        expect(evolved).to eq(regexp)
      end
    end

    context "when provided a string" do

      let(:regexp) do
        "\\A[123]"
      end

      let(:evolved) do
        Regexp.evolve(regexp)
      end

      it "returns the converted regexp" do
        expect(evolved).to eq(/\A[123]/)
      end
    end

    context "when provided an array" do

      context "when the elements are regexps" do

        let(:regexp) do
          /\A[123]/
        end

        let(:array) do
          [ regexp ]
        end

        let(:evolved) do
          Regexp.evolve(array)
        end

        it "returns the regexps" do
          expect(evolved).to eq([ regexp ])
        end

        it "does not evolve in place" do
          expect(evolved).to_not equal(array)
        end
      end

      context "when the elements are strings" do

        let(:regexp) do
          "\\A[123]"
        end

        let(:evolved) do
          Regexp.evolve([ regexp ])
        end

        it "returns the regexps" do
          expect(evolved).to eq([ /\A[123]/ ])
        end
      end
    end
  end

  describe "#regexp?" do

    let(:regexp) do
      /\A[123]/
    end

    it "returns true" do
      expect(regexp).to be_regexp
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
mongoid-7.3.5 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.3.4 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.11 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.6 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.3.3 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.3.2 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.5 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.10 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.9 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.4 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.3.1 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.3.0 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.3 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.8 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.2 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.1 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.7 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.2.0 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb
mongoid-7.1.6 spec/mongoid/criteria/queryable/extensions/regexp_spec.rb