Sha256: a15d1b25b6c865a2ee991059db99fe6123b55d9175a984d9f47cb41dd6cda76a

Contents?: true

Size: 1.23 KB

Versions: 27

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Mongoid::Extensions::Regexp do

  describe ".demongoize" do

    let(:value) do
      Regexp.demongoize(/[^abc]/)
    end

    it "returns the provided value" do
      expect(value).to eq(/[^abc]/)
    end
  end

  describe ".mongoize" do

    context "when providing a regex" do

      let(:value) do
        Regexp.mongoize(/[^abc]/)
      end

      it "returns the provided value" do
        expect(value).to eq(/[^abc]/)
      end
    end

    context "when providing a string" do

      let(:value) do
        Regexp.mongoize("[^abc]")
      end

      it "returns the provided value as a regex" do
        expect(value).to eq(/[^abc]/)
      end


      context "when the string is empty" do

        let(:value) do
          Regexp.mongoize("")
        end

        it "returns an empty regex" do
          expect(value).to eq(//)
        end
      end
    end

    context "when the value is nil" do

      let(:value) do
        Regexp.mongoize(nil)
      end

      it "returns the nil" do
        expect(value).to be_nil
      end
    end
  end

  describe "#mongoize" do

    it "returns self" do
      expect(/[^abc]/.mongoize).to eq(/[^abc]/)
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

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