Sha256: 4fca012e6457affca2e293cb69acdd29e62c849bdc6c38691e9951dddf0f967d

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class IndexingTest < Test::Unit::TestCase
  context "Indexing" do
    setup do
      @document = Doc do
        set_collection_name 'users'

        key :first_name, String
        key :last_name, String
        key :age, Integer
        key :date, Date
      end
      drop_indexes(@document)
    end

    should "allow creating index for a key" do
      @document.ensure_index :first_name
      @document.should have_index('first_name_1')
    end

    should "allow creating unique index for a key" do
      @document.ensure_index :first_name, :unique => true
      @document.should have_index('first_name_1')
    end

    should "allow creating index on multiple keys" do
      @document.ensure_index [[:first_name, 1], [:last_name, -1]]

      # order is different for different versions of ruby so instead of
      # just checking have_index('first_name_1_last_name_-1') I'm checking
      # the values of the indexes to make sure the index creation was successful
      @document.collection.index_information.detect do |index|
        keys = index[1]
        keys.include?(['first_name', 1]) && keys.include?(['last_name', -1])
      end.should_not be_nil
    end

    should "work with :index shortcut when defining key" do
      @document.key :father, String, :index => true
      @document.should have_index('father_1')
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
numon-0.0.1 test/functional/test_indexing.rb
mongo_mapper-0.7.2 test/functional/test_indexing.rb
mongo_mapper-0.7.1 test/functional/test_indexing.rb
mongo_mapper-unstable-2010.3.8 test/functional/test_indexing.rb
mongo_mapper-unstable-2010.3.5 test/functional/test_indexing.rb
mongo_mapper-unstable-2010.3.4 test/functional/test_indexing.rb
mongo_mapper-unstable-2010.3.3 test/functional/test_indexing.rb