Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have_index_for doesn't seem to work #208

Open
zedtux opened this issue Feb 19, 2018 · 2 comments
Open

have_index_for doesn't seem to work #208

zedtux opened this issue Feb 19, 2018 · 2 comments
Labels

Comments

@zedtux
Copy link

zedtux commented Feb 19, 2018

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?

@dblock dblock added the bug? label Feb 19, 2018
@dblock
Copy link
Collaborator

dblock commented Feb 19, 2018

Looks like a bug, appreciate a PR with a fix.

@zedtux
Copy link
Author

zedtux commented Feb 20, 2018

OK thank you @dblock for your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants