Skip to content

Commit

Permalink
Added tests for geoHaystack, enabled :bits parameter on 2d indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrees authored and durran committed Sep 19, 2012
1 parent cd7337f commit 30b7612
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/config/locales/en.yml
Expand Up @@ -152,8 +152,12 @@ en:
\_\_drop_dups: true|false\n \_\_drop_dups: true|false\n
\_\_name: 'index_name'\n \_\_name: 'index_name'\n
\_\_sparse: true|false\n \_\_sparse: true|false\n
\_\_unique: true|false\n\n \_\_unique: true|false\n
Valid types are: 1, -1, '2d'\n\n \_\_min: 1\n
\_\_max: 1\n
\_\_bits: 26\n
\_\_bucket_size : 1\n
Valid types are: 1, -1, '2d', 'geoHaystack'\n\n
Example:\n Example:\n
\_\_class Band\n \_\_class Band\n
\_\_\_\_include Mongoid::Document\n \_\_\_\_include Mongoid::Document\n
Expand Down
1 change: 1 addition & 0 deletions lib/mongoid/indexes.rb
Expand Up @@ -98,6 +98,7 @@ def index(spec, options = nil)
def normalize_index_options(options) def normalize_index_options(options)
opts = options || {} opts = options || {}
opts[:dropDups] = opts.delete(:drop_dups) if opts.has_key?(:drop_dups) opts[:dropDups] = opts.delete(:drop_dups) if opts.has_key?(:drop_dups)
opts[:bucketSize] = opts.delete(:bucket_size) if opts.has_key?(:bucket_size)
opts opts
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/indexes/validators/options.rb
Expand Up @@ -7,7 +7,7 @@ module Validators
module Options module Options
extend self extend self


VALID_OPTIONS = [ :background, :drop_dups, :name, :sparse, :unique, :max, :min, :bucketSize ] VALID_OPTIONS = [ :background, :drop_dups, :name, :sparse, :unique, :max, :min, :bits, :bucket_size ]
VALID_TYPES = [ 1, -1, "2d", "geoHaystack" ] VALID_TYPES = [ 1, -1, "2d", "geoHaystack" ]


# Validate the index specification. # Validate the index specification.
Expand Down
19 changes: 17 additions & 2 deletions spec/mongoid/indexes_spec.rb
Expand Up @@ -184,15 +184,30 @@ def self.hereditary?
context "when providing a geospacial index" do context "when providing a geospacial index" do


before do before do
klass.index({ location: "2d" }, { min: -200, max: 200 }) klass.index({ location: "2d" }, { min: -200, max: 200, bits: 32 })
end end


let(:options) do let(:options) do
klass.index_options[location: "2d"] klass.index_options[location: "2d"]
end end


it "sets the geospacial index" do it "sets the geospacial index" do
options.should eq({ min: -200, max: 200 }) options.should eq({ min: -200, max: 200, bits: 32 })
end
end

context "when providing a geo haystack index" do

before do
klass.index({ location: "geoHaystack" }, { min: -200, max: 200, bucket_size: 0.5 })
end

let(:options) do
klass.index_options[location: "geoHaystack"]
end

it "sets the geo haystack index" do
options.should eq({ min: -200, max: 200, bucketSize: 0.5 })
end end
end end


Expand Down

0 comments on commit 30b7612

Please sign in to comment.