Using validate_presence_of with strict validations

287 views Asked by At

I’m using the Shoulda gem. I’m using the validate_presence_of method. It is working nicely. It doesn’t seem to work, however, when using a strict validation. Example:

class Thing < ActiveRecord::Base
 validates :status, presence: true # works
 validates :status, presence: true, strict: true # does not work
end

describe Thing do
  let(:thing) { FactoryGirl.build_stubbed :thing }
  subject { thing }
  it { should validate_presence_of :status }
end

Any idea how I can make it work? Maybe strict validations just aren’t supported? I can’t seem to find information about this in the repository or in the docs.

1

There are 1 answers

0
spickermann On BEST ANSWER

I think strict validators are tested like this:

describe Thing do
  subject(:thing) { FactoryGirl.build_stubbed :thing }

  it { should validate_presence_of(:status).strict }
end