Sha256: 1ebb46e595577aee3834dbdef42acd64adb4706543ee73c6c55870165bda75f5

Contents?: true

Size: 1.27 KB

Versions: 62

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'

module Workarea
  class StringIdTest < TestCase
    class FooModel
      include Mongoid::Document
      field :_id, type: StringId, default: -> { BSON::ObjectId.new }
    end

    def test_querying_on_id
      model = FooModel.create!
      assert(model.id.is_a?(BSON::ObjectId))
      assert_equal(model, FooModel.find(model.id))

      found = FooModel.find(model.id.to_s)
      assert_equal(model, found)
      assert(found.id.is_a?(BSON::ObjectId))

      model = FooModel.create!(id: '5b900d884907b7417f9c33d5')
      assert(model.id.is_a?(BSON::ObjectId))

      found = FooModel.find('5b900d884907b7417f9c33d5')
      assert(found.id.is_a?(BSON::ObjectId))
      assert_equal(model, found)

      found = FooModel.find(BSON::ObjectId.from_string('5b900d884907b7417f9c33d5'))
      assert(found.id.is_a?(BSON::ObjectId))
      assert_equal(model, found)

      string_model = FooModel.create!(id: 'foobar')
      assert(string_model.id.is_a?(String))

      found = FooModel.find('foobar')
      assert(found.id.is_a?(String))
      assert_equal(string_model, found)

      mixed = FooModel.in(id: ['foobar', '5b900d884907b7417f9c33d5']).to_a
      assert_equal(2, mixed.count)
      assert(mixed.include?(model))
      assert(mixed.include?(string_model))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 test/lib/workarea/string_id_test.rb
workarea-core-3.4.36 test/lib/workarea/string_id_test.rb
workarea-core-3.5.14 test/lib/workarea/string_id_test.rb
workarea-core-3.4.35 test/lib/workarea/string_id_test.rb
workarea-core-3.5.13 test/lib/workarea/string_id_test.rb
workarea-core-3.4.34 test/lib/workarea/string_id_test.rb
workarea-core-3.5.12 test/lib/workarea/string_id_test.rb
workarea-core-3.4.33 test/lib/workarea/string_id_test.rb
workarea-core-3.5.11 test/lib/workarea/string_id_test.rb
workarea-core-3.5.10 test/lib/workarea/string_id_test.rb
workarea-core-3.4.32 test/lib/workarea/string_id_test.rb
workarea-core-3.5.9 test/lib/workarea/string_id_test.rb
workarea-core-3.4.31 test/lib/workarea/string_id_test.rb
workarea-core-3.5.8 test/lib/workarea/string_id_test.rb
workarea-core-3.4.30 test/lib/workarea/string_id_test.rb
workarea-core-3.5.7 test/lib/workarea/string_id_test.rb
workarea-core-3.4.29 test/lib/workarea/string_id_test.rb
workarea-core-3.5.6 test/lib/workarea/string_id_test.rb
workarea-core-3.4.28 test/lib/workarea/string_id_test.rb
workarea-core-3.5.5 test/lib/workarea/string_id_test.rb