Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 30b76126af1a4457c93b718e21d38ea4f90e0610 1 parent cd7337f
Brad Rees bradrees authored durran committed
8 lib/config/locales/en.yml
@@ -152,8 +152,12 @@ en:
152 152 \_\_drop_dups: true|false\n
153 153 \_\_name: 'index_name'\n
154 154 \_\_sparse: true|false\n
155   - \_\_unique: true|false\n\n
156   - Valid types are: 1, -1, '2d'\n\n
  155 + \_\_unique: true|false\n
  156 + \_\_min: 1\n
  157 + \_\_max: 1\n
  158 + \_\_bits: 26\n
  159 + \_\_bucket_size : 1\n
  160 + Valid types are: 1, -1, '2d', 'geoHaystack'\n\n
157 161 Example:\n
158 162 \_\_class Band\n
159 163 \_\_\_\_include Mongoid::Document\n
1  lib/mongoid/indexes.rb
@@ -98,6 +98,7 @@ def index(spec, options = nil)
98 98 def normalize_index_options(options)
99 99 opts = options || {}
100 100 opts[:dropDups] = opts.delete(:drop_dups) if opts.has_key?(:drop_dups)
  101 + opts[:bucketSize] = opts.delete(:bucket_size) if opts.has_key?(:bucket_size)
101 102 opts
102 103 end
103 104 end
2  lib/mongoid/indexes/validators/options.rb
@@ -7,7 +7,7 @@ module Validators
7 7 module Options
8 8 extend self
9 9
10   - VALID_OPTIONS = [ :background, :drop_dups, :name, :sparse, :unique, :max, :min, :bucketSize ]
  10 + VALID_OPTIONS = [ :background, :drop_dups, :name, :sparse, :unique, :max, :min, :bits, :bucket_size ]
11 11 VALID_TYPES = [ 1, -1, "2d", "geoHaystack" ]
12 12
13 13 # Validate the index specification.
19 spec/mongoid/indexes_spec.rb
@@ -184,7 +184,7 @@ def self.hereditary?
184 184 context "when providing a geospacial index" do
185 185
186 186 before do
187   - klass.index({ location: "2d" }, { min: -200, max: 200 })
  187 + klass.index({ location: "2d" }, { min: -200, max: 200, bits: 32 })
188 188 end
189 189
190 190 let(:options) do
@@ -192,7 +192,22 @@ def self.hereditary?
192 192 end
193 193
194 194 it "sets the geospacial index" do
195   - options.should eq({ min: -200, max: 200 })
  195 + options.should eq({ min: -200, max: 200, bits: 32 })
  196 + end
  197 + end
  198 +
  199 + context "when providing a geo haystack index" do
  200 +
  201 + before do
  202 + klass.index({ location: "geoHaystack" }, { min: -200, max: 200, bucket_size: 0.5 })
  203 + end
  204 +
  205 + let(:options) do
  206 + klass.index_options[location: "geoHaystack"]
  207 + end
  208 +
  209 + it "sets the geo haystack index" do
  210 + options.should eq({ min: -200, max: 200, bucketSize: 0.5 })
196 211 end
197 212 end
198 213

0 comments on commit 30b7612

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