Skip to content

Commit 2ec77f4

Browse files
committed
Fixes to index options
1 parent 02a1c74 commit 2ec77f4

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

lib/mongoid_monkey.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'patches/atomic'
44
require 'patches/big_decimal'
55
require 'patches/db_commands'
6+
require 'patches/index_options'
67
require 'patches/instrument'
78
require 'patches/reorder'
89
require 'patches/only_pluck_localized'

lib/patches/index_options.rb

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# Backport Mongoid 4 :touch option for #embedded_in to Mongoid 3.
1+
# Backport Mongoid 6 index options to Mongoid 3 and 4.
22

33
if Mongoid::VERSION =~ /\A3\./
44

5-
module Mongoid
6-
module Indexes
7-
module Validators
8-
9-
module Options
5+
::Mongoid::Indexes::Validators::Options.send(:remove_const, :VALID_OPTIONS)
6+
module Mongoid::Indexes::Validators::Options
107
VALID_OPTIONS = [
118
:background,
129
:database,
@@ -30,17 +27,11 @@ module Options
3027
:collation
3128
]
3229
end
33-
end
34-
end
35-
end
3630

3731
elsif Mongoid::VERSION =~ /\A4\./
3832

39-
module Mongoid
40-
module Indexable
41-
module Validators
42-
43-
module Options
33+
::Mongoid::Indexable::Validators::Options.send(:remove_const, :VALID_OPTIONS)
34+
module Mongoid::Indexable::Validators::Options
4435
VALID_OPTIONS = [
4536
:background,
4637
:database,
@@ -65,7 +56,3 @@ module Options
6556
]
6657
end
6758
end
68-
end
69-
end
70-
71-
end

spec/unit/index_options_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require "spec_helper"
2+
3+
if Mongoid::VERSION =~ /\A[34]\./
4+
5+
describe 'Index Valid Options' do
6+
let(:mod){ Mongoid::VERSION =~ /\A3\./ ? Mongoid::Indexes::Validators : Mongoid::Indexable::Validators }
7+
let(:exp) do
8+
[ :background,
9+
:database,
10+
:default_language,
11+
:language_override,
12+
:drop_dups,
13+
:name,
14+
:sparse,
15+
:unique,
16+
:max,
17+
:min,
18+
:bits,
19+
:bucket_size,
20+
:expire_after_seconds,
21+
:weights,
22+
:storage_engine,
23+
:sphere_version,
24+
:text_version,
25+
:version,
26+
:partial_filter_expression,
27+
:collation ]
28+
end
29+
it { expect(mod::Options::VALID_OPTIONS).to eq(exp) }
30+
end
31+
end

0 commit comments

Comments
 (0)