Skip to content

Commit

Permalink
Fixes to index options
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Feb 21, 2017
1 parent 02a1c74 commit 2ec77f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/mongoid_monkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'patches/atomic'
require 'patches/big_decimal'
require 'patches/db_commands'
require 'patches/index_options'
require 'patches/instrument'
require 'patches/reorder'
require 'patches/only_pluck_localized'
Expand Down
23 changes: 5 additions & 18 deletions lib/patches/index_options.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Backport Mongoid 4 :touch option for #embedded_in to Mongoid 3.
# Backport Mongoid 6 index options to Mongoid 3 and 4.

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

module Mongoid
module Indexes
module Validators

module Options
::Mongoid::Indexes::Validators::Options.send(:remove_const, :VALID_OPTIONS)
module Mongoid::Indexes::Validators::Options
VALID_OPTIONS = [
:background,
:database,
Expand All @@ -30,17 +27,11 @@ module Options
:collation
]
end
end
end
end

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

module Mongoid
module Indexable
module Validators

module Options
::Mongoid::Indexable::Validators::Options.send(:remove_const, :VALID_OPTIONS)
module Mongoid::Indexable::Validators::Options
VALID_OPTIONS = [
:background,
:database,
Expand All @@ -65,7 +56,3 @@ module Options
]
end
end
end
end

end
31 changes: 31 additions & 0 deletions spec/unit/index_options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "spec_helper"

if Mongoid::VERSION =~ /\A[34]\./

describe 'Index Valid Options' do
let(:mod){ Mongoid::VERSION =~ /\A3\./ ? Mongoid::Indexes::Validators : Mongoid::Indexable::Validators }
let(:exp) do
[ :background,
:database,
:default_language,
:language_override,
:drop_dups,
:name,
:sparse,
:unique,
:max,
:min,
:bits,
:bucket_size,
:expire_after_seconds,
:weights,
:storage_engine,
:sphere_version,
:text_version,
:version,
:partial_filter_expression,
:collation ]
end
it { expect(mod::Options::VALID_OPTIONS).to eq(exp) }
end
end

0 comments on commit 2ec77f4

Please sign in to comment.