mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
707d87dbd6
With the new Rails 5 behavior, `belong_to` will check to ensure that the association has a presence validation on it. In some cases, however, this is not desirable. For instance, say we have this setup: class Employee < ApplicationRecord # Assume belongs_to_required_by_default is true belongs_to :manager before_validation :add_manager private def add_manager self.manager = Manager.create end end In this case, even though the association is effectively defined with `required: true`, the ensuing presence validation never fails, because `manager` is always set to something before validations kick off. So this test won't work: it { should belong_to(:manager) } To get around this, this commit allows us to say: it { should belong_to(:manager).without_presence_validation } which instructs the matcher not to test for any presence (or absence, for that matter) of a presence validation, mimicking the pre-Rails 5 behavior. |
||
---|---|---|
.. | ||
acceptance | ||
support | ||
unit/shoulda/matchers | ||
warnings_spy | ||
acceptance_spec_helper.rb | ||
doublespeak_spec_helper.rb | ||
report_warnings.rb | ||
spec_helper.rb | ||
unit_spec_helper.rb | ||
warnings_spy.rb |