Skip to content

have_index_for doesn't seem to work #208

Open
@zedtux

Description

@zedtux

I'm using Mongoid 5.1.6 in a Rails 4.2.2 application.

I'm able to test all the Mongoid things of my models excepted the indexes.

I have a model like this:

class ConversationUnreadMessage
  include Mongoid::Document
  include Mongoid::Timestamps::Short
  include MongoSerializer

  # ~~~~ Fields ~~~~
  field :o, as: :operator_id, type: Integer
  field :c, as: :conversation_id, type: String
  field :m, as: :conversation_message_id, type: String

  # ~~~~ Index ~~~~
  index({ operator_id: 1, conversation_id: 1 }, background: true)
end

And my spec file like this:

require 'rails_helper'

RSpec.describe ConversationUnreadMessage, type: :model do
  describe 'Fields' do
    it { is_expected.to have_field(:o).with_alias(:operator_id).of_type(Integer) }
    it { is_expected.to have_field(:c).with_alias(:conversation_id).of_type(String) }
    it { is_expected.to have_field(:m).with_alias(:conversation_message_id).of_type(String) }
  end

  describe 'Indexes' do
    it { is_expected.to have_index_for(operator_id: 1, conversation_id: 1).with_options(background: true) }
  end
end

The tests are failing with the following:

Failures:

  1) ConversationUnreadMessage Indexes should have an index for {:operator_id=>1, :conversation_id=>1} with options of {:background=>true}
     Failure/Error: it { is_expected.to have_index_for(operator_id: 1, conversation_id: 1).with_options(background: true) }
       Expected ConversationUnreadMessage to have an index for {:operator_id=>1, :conversation_id=>1} with options of {:background=>true}, got no index for {:operator_id=>1, :conversation_id=>1}
      ...

I did it following this gem's README.md file instructions.

Is there anything else that shall be done in order to get this to work? Or should it be a bug of this gem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions