Sha256: afa1b9e64f3d3f54de01944e7d22b0972993f6054d82cbd1c980b8a1eeca2f1e

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

require "spec_helper"

describe Mongoid::Matchable::Exists do

  describe "#matches?" do

    context "when checking for existence" do

      context "when the value exists" do

        let(:matcher) do
          described_class.new("Test")
        end

        it "returns true" do
          expect(matcher.matches?("$exists" => true)).to be_true
        end
      end

      context "when the value does not exist" do

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

        it "returns false" do
          expect(matcher.matches?("$exists" => true)).to be_false
        end
      end
    end

    context "when checking for nonexistence" do

      context "when the value exists" do

        let(:matcher) do
          described_class.new("Test")
        end

        it "returns false" do
          expect(matcher.matches?("$exists" => false)).to be_false
        end
      end

      context "when the value does not exist" do

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

        it "returns true" do
          expect(matcher.matches?("$exists" => false)).to be_true
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
sepastian-mongoid-rails4-4.0.1.alpha spec/mongoid/matchable/exists_spec.rb
sepastian-mongoid-rails4-4.0.0.alpha spec/mongoid/matchable/exists_spec.rb
mongoid_heroku_stable-4.0.0 spec/mongoid/matchable/exists_spec.rb
mongoid_rails4-4.0.0 spec/mongoid/matchable/exists_spec.rb