Skip to content
Browse files

Added tests for geoHaystack, enabled :bits parameter on 2d indexes

  • Loading branch information...
1 parent cd7337f commit 30b76126af1a4457c93b718e21d38ea4f90e0610 @bradrees bradrees committed with durran Sep 18, 2012
Showing with 25 additions and 5 deletions.
  1. +6 −2 lib/config/locales/en.yml
  2. +1 −0 lib/mongoid/indexes.rb
  3. +1 −1 lib/mongoid/indexes/validators/options.rb
  4. +17 −2 spec/mongoid/indexes_spec.rb
View
8 lib/config/locales/en.yml
@@ -152,8 +152,12 @@ en:
\_\_drop_dups: true|false\n
\_\_name: 'index_name'\n
\_\_sparse: true|false\n
- \_\_unique: true|false\n\n
- Valid types are: 1, -1, '2d'\n\n
+ \_\_unique: true|false\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
\_\_class Band\n
\_\_\_\_include Mongoid::Document\n
View
1 lib/mongoid/indexes.rb
@@ -98,6 +98,7 @@ def index(spec, options = nil)
def normalize_index_options(options)
opts = options || {}
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
end
end
View
2 lib/mongoid/indexes/validators/options.rb
@@ -7,7 +7,7 @@ module Validators
module Options
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" ]
# Validate the index specification.
View
19 spec/mongoid/indexes_spec.rb
@@ -184,15 +184,30 @@ def self.hereditary?
context "when providing a geospacial index" do
before do
- klass.index({ location: "2d" }, { min: -200, max: 200 })
+ klass.index({ location: "2d" }, { min: -200, max: 200, bits: 32 })
end
let(:options) do
klass.index_options[location: "2d"]
end
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

0 comments on commit 30b7612

Please sign in to comment.
Something went wrong with that request. Please try again.