3

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?)

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

1 Answers1

2

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.

Tanzeeb Khalili
  • 7,324
  • 2
  • 23
  • 27