Skip to content

Commit

Permalink
Refactor spec, rename for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jul 4, 2013
1 parent 269fc6b commit a65d573
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/rails/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def undefined_indexes
# @example Remove undefined indexes.
# Rails::Mongoid.drop_undefined_indexes
#
# @return Hash{Class => Array(Hash)} The list of indexes that were removed by model.
def drop_undefined_indexes
# @return [ Hash{Class => Array(Hash)}] The list of indexes that were removed by model.
#
# @since 4.0.0
def remove_undefined_indexes
undefined_indexes.each do |model, indexes|
indexes.each do |index|
key = index['key'].symbolize_keys
Expand Down
20 changes: 13 additions & 7 deletions spec/rails/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,25 @@
Rails::Mongoid.create_indexes
end

subject do
let(:indexes) do
Rails::Mongoid.undefined_indexes
end

it { should eq({}) }
it "returns the removed indexes" do
expect(indexes).to be_empty
end

context "with extra index on model collection" do

before(:each) do
User.collection.indexes.create(account_expires: 1)
end

its(:keys) { should eq([User]) }
let(:names) do
indexes[User].map{ |index| index['name'] }
end

it "should have single index returned" do
names = subject[User].map{ |index| index['name'] }
expect(names).to eq(['account_expires_1'])
end
end
Expand All @@ -111,14 +115,16 @@
before(:each) do
Rails::Mongoid.create_indexes
indexes.create(account_expires: 1)
Rails::Mongoid.drop_undefined_indexes
Rails::Mongoid.remove_undefined_indexes
end

subject do
let(:removed_indexes) do
Rails::Mongoid.undefined_indexes
end

it { should eq({}) }
it "returns the removed indexes" do
expect(removed_indexes).to be_empty
end
end

describe ".remove_indexes" do
Expand Down

0 comments on commit a65d573

Please sign in to comment.