Closed ArcDlrt closed 5 years ago
You're getting this because the belong_to
matcher now tests whether your association is allowed to be nil. If you have some sort of action that attempts to create a ProfileRiskVariable without profile_risk_variable_id
being set, you will likely run into the same error — the matcher is just revealing a code path that you may have never executed before.
It looks like in your range_criteria?
method, criteria_type
is delegating to profile_risk_variable
, but if profile_risk_variable
is nil, this won't work because you can't call profile_risk_variable
on nil. You might want to add allow_nil: true
to the delegate
line.
I see, it make sense since now the relationship is by default required.
Thank you very much
No problem!
For others that land on this thread, you can also use the without_validating_presence
modifier to prevent the nil
check from running when you know it won't be nil
.
it { should belong_to(:profile_risk_variable).without_validating_presence }
After upgrading the gem from 3.1.2 to 4.0.1 the following spec failded
The result of running this spec is an
undefined method
criteria_type' for nil:NilClass`This is the relevant code for the example given
This was run using RoR 5.2.0, Ruby 2.4.3 and shoulda-matchers 4.0.1