Sha256: 1beefdbe87e6ddaf94fac5fe8081550560ba431c8d214f4bcdc9e14654145f55

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

describe Mongoid::Extensions::Symbol do

  describe ".demongoize" do

    context "when the object is not a symbol" do

      it "returns the symbol" do
        Symbol.demongoize("test").should eq(:test)
      end
    end

    context "when the object is nil" do

      it "returns nil" do
        Symbol.demongoize(nil).should be_nil
      end
    end
  end

  describe "#mongoid_id?" do

    context "when the string is id" do

      it "returns true" do
        :id.should be_mongoid_id
      end
    end

    context "when the string is _id" do

      it "returns true" do
        :_id.should be_mongoid_id
      end
    end

    context "when the string contains id" do

      it "returns false" do
        :identity.should_not be_mongoid_id
      end
    end

    context "when the string contains _id" do

      it "returns false" do
        :something_id.should_not be_mongoid_id
      end
    end
  end

  describe ".mongoize" do

    context "when the object is not a symbol" do

      it "returns the symbol" do
        Symbol.mongoize("test").should eq(:test)
      end
    end

    context "when the object is nil" do

      it "returns nil" do
        Symbol.mongoize(nil).should be_nil
      end
    end
  end

  describe "#mongoize" do

    it "returns self" do
      :test.mongoize.should eq(:test)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-3.1.7 spec/mongoid/extensions/symbol_spec.rb
mongoid-3.1.6 spec/mongoid/extensions/symbol_spec.rb
mongoid-3.1.5 spec/mongoid/extensions/symbol_spec.rb