Sha256: 5d9efb18e21f58616fe472535dca8878a72c780a04ebd86608b90bb6e88cd240

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"

describe Mongoid::Matchable::Regexp do

  let(:matcher) do
    described_class.new(attribute)
  end

  let(:attribute) do
    'Emily'
  end

  describe '#_matches?' do

    context 'when a BSON::Regexp::Raw object is passed' do

      let(:regexp) do
        BSON::Regexp::Raw.new('^Em')
      end

      it 'compiles the regexp object to a native regexp for the matching' do
        expect(matcher._matches?(regexp)).to be(true)
      end

      context 'when the value does not match the attribute' do

        let(:attribute) do
          'ily'
        end

        it 'compiles the regexp object to a native regexp for the matching' do
          expect(matcher._matches?(regexp)).to be(false)
        end
      end
    end

    context 'when a native Regexp object is passed' do

      let(:regexp) do
        /^Em/
      end

      it 'calls super with the native regexp' do
        expect(matcher._matches?(regexp)).to be(true)
      end

      context 'when the value does not match the attribute' do

        let(:attribute) do
          'ily'
        end

        it 'compiles the regexp object to a native regexp for the matching' do
          expect(matcher._matches?(regexp)).to be(false)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
mongoid-6.4.8 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.7 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.5 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.7 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.6 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.5 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.4 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.4 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.3 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.2 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.2 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.1 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.1 spec/mongoid/matchable/regexp_spec.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.0 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.4.0 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.3.0 spec/mongoid/matchable/regexp_spec.rb
mongoid-6.2.1 spec/mongoid/matchable/regexp_spec.rb
mongoid-7.0.0.beta spec/mongoid/matchable/regexp_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/spec/mongoid/matchable/regexp_spec.rb