Fixed index ordering

This commit is contained in:
Kyle Banker 2009-11-17 13:20:57 -05:00
parent e8748651b5
commit cd44c3c918
5 changed files with 27 additions and 1 deletions

View File

@ -355,6 +355,7 @@ Sean Cribbs, seancribbs on github
Sunny Hirai
* Suggested hashcode fix for Mongo::ObjectID
* Noted index ordering bug.
= License

View File

@ -505,4 +505,5 @@ EOS
indexes.join("_")
end
end
end

View File

@ -422,7 +422,7 @@ module Mongo
sel = {:ns => full_collection_name(collection_name)}
info = {}
Cursor.new(Collection.new(self, SYSTEM_INDEX_COLLECTION), :selector => sel).each { |index|
info[index['name']] = index['key'].to_a
info[index['name']] = index['key'].map
}
info
end

View File

@ -69,6 +69,7 @@ class OrderedHash < Hash
@ordered_keys.each { |k| yield k, self[k] }
self
end
alias :each_pair :each
def values
collect { |k, v| v }

View File

@ -398,4 +398,27 @@ class TestCollection < Test::Unit::TestCase
assert_equal 1, @collection.size
end
end
context "Creating indexes " do
setup do
@collection = @@db.collection('test-collection')
end
should "generate indexes in the proper order" do
@collection.expects(:insert_documents) do |sel, coll, safe|
assert_equal 'b_1_a_1', sel[:name]
end
@collection.create_index([['b', 1], ['a', 1]])
end
context "with an index created" do
setup do
@collection.create_index([['b', 1], ['a', 1]])
end
should "return properly ordered index information" do
assert_equal [['b', 1], ['a', 1]], @collection.index_information["b_1_a_1"]
end
end
end
end