Sha256: 773781ff538be57c9fadc11e40d1bcc138d375cb1c8f0b9487f2ef9d01072007

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Integer do

  describe ".evolve" do

    context "when provided a string" do

      context "when the string is a number" do

        context "when the string is an integer" do

          it "returns an integer" do
            expect(described_class.evolve("1")).to eq(1)
          end
        end

        context "when the string is a float" do

          it "converts it to a float" do
            expect(described_class.evolve("2.23")).to eq(2.23)
          end
        end

        context "when the string ends in ." do

          it "returns an integer" do
            expect(described_class.evolve("2.")).to eq(2)
          end
        end
      end

      context "when the string is not a number" do

        it "returns the string" do
          expect(described_class.evolve("testing")).to eq("testing")
        end
      end
    end
  end

  context "when provided a number" do

    context "when the number is an integer" do

      it "returns an integer" do
        expect(described_class.evolve(1)).to eq(1)
      end
    end

    context "when the number is a float" do

      it "returns the float" do
        expect(described_class.evolve(2.23)).to eq(2.23)
      end
    end
  end

  context "when provided nil" do

    it "returns nil" do
      expect(described_class.evolve(nil)).to be_nil
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

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