Skip to content

Commit

Permalink
Delegate index methods to the collection
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Nov 7, 2011
1 parent a46ba12 commit 7a8d0dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/mongo_mapper/plugins/indexes.rb
Expand Up @@ -5,9 +5,8 @@ module Indexes
extend ActiveSupport::Concern

module ClassMethods
def ensure_index(spec, options={})
collection.create_index(spec, options)
end
extend Forwardable
def_delegators :collection, :ensure_index, :create_index, :drop_index, :drop_indexes
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/functional/test_indexes.rb
Expand Up @@ -12,6 +12,14 @@ class IndexingTest < Test::Unit::TestCase
end
teardown { drop_indexes(@document) }

[:create_index, :ensure_index, :drop_index, :drop_indexes].each do |method|
should "delegate #{method} to collection" do
@document.stubs(:collection).returns(mock(:name => :foo))
@document.collection.expects(method).with(:arg)
@document.send(method, :arg)
end
end

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

0 comments on commit 7a8d0dc

Please sign in to comment.