Sha256: 04276f7600bdf815550d694ee816d73c6359e7d36b69f7b538b3b4a5c4a5ed6d

Contents?: true

Size: 1.06 KB

Versions: 35

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require "spec_helper"

describe Mongoid::Criteria::Queryable::Extensions::Numeric::ClassMethods do

  let(:host) do
    Class.new do
      include Mongoid::Criteria::Queryable::Extensions::Numeric::ClassMethods
    end.new
  end

  describe "#__numeric__" do

    let(:actual) { host.__numeric__(str) }

    context "when the string is a whole number" do

      let(:str) { '123' }

      it "returns the value as integer" do
        expect(actual).to eq(123)
      end
    end

    context "when the string is a floating point number" do

      let(:str) { '123.45' }

      it "returns the value as a float" do
        expect(actual).to eq(123.45)
      end
    end

    context "when the string is a dot only" do

      let(:str) { '.' }

      it "returns zero" do
        expect(actual).to eq(0)
      end
    end

    context "when the string is a number with fractional part consisting of zeros" do

      let(:str) { '12.000' }

      it "returns the value as integer" do
        expect(actual).to eq(12)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

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