I have this model code:
validates_presence_of :setting_id
validates_presence_of :user_id
validates_presence_of :topic_id, if: :direct?
I have these rspec tests:
it { should validate_presence_of :setting_id }
it { should validate_presence_of :user_id }
it { should validate_presence_of(:topic_id).if(:direct?) }
The first 2 tests work ok.
The last one gives an error of:
undefined method 'if' for #<Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher:0x007fda6a5c6268>
How can I add a similar tests for code fragment for the last presence of validation for (:topic_id).if(:direct?)
From the source code for shoulda-matchers, it looks like the :if condition is not supported. You will need to test this manually with stubbed values for the direct? method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With