mongoid-rspec icon indicating copy to clipboard operation
mongoid-rspec copied to clipboard

validate_length_of undefined method `to_allow'

Open dks17 opened this issue 7 years ago • 3 comments

I have:

class User
  include Mongoid::Document

  field  :name, type: String

  validates_length_of :name, in: 1..100, allow_nil: true
end
require 'rails_helper'

RSpec.describe User, type: :model do
    it { is_expected.to validate_length_of(:name).within(1..100).to_allow(nil: true) }
end

and caught the error:

Failure/Error: it { is_expected.to validate_length_of(:name).within(1..100).to_allow(nil: true) }
     NoMethodError:
       undefined method `to_allow' for #<Mongoid::Matchers::Validations::ValidateLengthOfMatcher:0x000055f3d7c01158>
       Did you mean?  to_yaml

Did I make something wrong or it is a bug? Rails validates_length_of validator.

dks17 avatar Feb 28 '18 05:02 dks17

Maybe just not implemented?

dblock avatar Feb 28 '18 14:02 dblock

Yes. I checked code of the gem. Looks like is not implemented. This issue should be closed or labelled as new feature.

dks17 avatar Mar 19 '18 12:03 dks17

Reopened and relabeled.

dblock avatar Mar 19 '18 13:03 dblock