Sha256: d4f70065ba42eef1a2f58f235163b9191321f10aa6789fbae151c9bbf5ecafe1

Contents?: true

Size: 1.31 KB

Versions: 64

Compression:

Stored size: 1.31 KB

Contents

require 'test_helper'

class IndexingTest < Test::Unit::TestCase
  context "Indexing" do
    setup do
      @document = Doc do
        key :first_name, String
        key :last_name, String
        key :age, Integer
        key :date, Date
      end
    end
    teardown { drop_indexes(@document) }

    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[0]
        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

64 entries across 64 versions & 7 rubygems

Version Path
mongo_mapper-unstable-2010.07.20 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.19 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.18 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.16 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.15 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.14 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.13 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.12 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.09 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.08 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.07 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.06 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.05 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.02 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.07.01 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.06.30 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.06.29 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.06.28 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.06.25 test/functional/test_indexes.rb
mongo_mapper-unstable-2010.06.24 test/functional/test_indexes.rb