-1

I have simple model that looks like this:

class User < ActiveRecord::Base
  belongs_to :administration
  validates :administration, presence: true, allow_blank: true
end

and spec that looks like this:

require 'spec_helper'

describe User, type: :model do
  it { is_expected.to validate_presence_of(:administration).allow_blank }
end

running this spec returns me:

NoMethodError:
       undefined method `allow_blank' for #<Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher:0x0000000b7f27a8>

Why?

Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133

1 Answers1

0

it { should allow_value("", nil).for(:administration) }

should work.

Santanu
  • 960
  • 10
  • 14
  • you copied it from old answer. Since then there is a new recommended `expect` syntax. – Andrey Deineko Jul 16 '15 at 09:57
  • You can write, ```subject { user }``` ```expect(subject).to allow_value("", nil).for(:administration)```. But I have some confusion with this ```subject ``` syntax. So I always avoid it. :) – Santanu Jul 16 '15 at 11:16