EDIT: As per @max suggestion, I'm changing my model to use enum instead, however I can't test it for default state:
it { is_expected.to validate_inclusion_of(:status).to_allow("draft", "published") }
Works fine with the following code in the model:
validates :status, :inclusion => { :in => ["draft", "published"] }
But this part still fails:
it { is_expected.to have_field(:status).with_default_value_of("draft") }
Please note that I'm using Mongoid. I have this in my model spec:
OLD question - kept for reference?
it { is_expected.to have_field(:published).of_type(Boolean).with_default_value_of(false) }
And in my model I have this:
field :published, type: Mongoid::Boolean, default: false
Yet is not working. I've tried removing the Mongoid bit but get the same error:
Failure/Error: it { is_expected.to have_field(:published).of_type(Boolean).with_default_value_of(false) }
Expected Post to have field named "published" of type Boolean with default value of false, got field "published" of type Mongoid::Boolean
Note: I've also tried:
field :published, type: Boolean, default: false
And have added the following method in my model:
after_initialize :set_published, :if => :new_record?
then
private
def set_published
self.published ||= false
end
But nothing seems to work. What am I missing?