Sha256: b06bd5b9cd1d6c9388a20fa60113051dc6eb79476de378183eacdb12ccda9549

Contents?: true

Size: 1.83 KB

Versions: 27

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Mongoid::StringifiedSymbol do

  describe ".demongoize" do

    context "when the object is not a symbol" do

      it "returns the symbol" do
        expect(Mongoid::StringifiedSymbol.demongoize("test")).to eq(:test)
      end
    end

    context "when the object is a symbol" do

      it "returns the symbol" do
        expect(Mongoid::StringifiedSymbol.demongoize(:test)).to eq(:test)
      end
    end

    context "when the object is a BSON Symbol" do

      it "returns a symbol" do
        expect(Mongoid::StringifiedSymbol.demongoize(BSON::Symbol::Raw.new(:test))).to eq(:test)
      end
    end


    context "when the object is an integer" do

      it "returns a symbol" do
        expect(Mongoid::StringifiedSymbol.demongoize(14)).to eq(:"14")
      end
    end

    context "when the object is nil" do

      it "returns nil" do
        expect(Mongoid::StringifiedSymbol.demongoize(nil)).to be_nil
      end
    end
  end

  describe ".mongoize" do

    context "when the object is not a symbol" do

      it "returns the object" do
        expect(Mongoid::StringifiedSymbol.mongoize("test")).to eq("test")
      end

      it "returns the string" do
        expect(Mongoid::StringifiedSymbol.mongoize([0,1,2])).to eq("[0, 1, 2]")
      end

      it "returns the string" do
        expect(Mongoid::StringifiedSymbol.mongoize(2)).to eq("2")
      end
    end

    context "when the object is a symbol" do

      it "returns a string" do
        expect(Mongoid::StringifiedSymbol.mongoize(:test)).to eq("test")
      end
    end

    context "when the object is nil" do

      it "returns nil" do
        expect(Mongoid::StringifiedSymbol.mongoize(nil)).to be_nil
      end
    end
  end

  describe "#mongoize" do

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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mongoid-8.1.9 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.9 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.8 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.7 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.6 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.8 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.5 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.4 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.7 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.3 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.2 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.6 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-7.5.4 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.1 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.5 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.1.0 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-7.5.3 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.4 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-8.0.3 spec/mongoid/extensions/stringified_symbol_spec.rb
mongoid-7.5.2 spec/mongoid/extensions/stringified_symbol_spec.rb