1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers
Elliot Winkler 707d87dbd6 Add without_presence_validation q to belong_to
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.
2019-02-14 17:48:26 -07:00
..
action_controller Use head instead of render: nothing in tests 2017-09-28 01:08:55 -05:00
active_model Ensure allow_nil on inclusion returns self 2019-02-14 03:31:50 -07:00
active_record Add without_presence_validation q to belong_to 2019-02-14 17:48:26 -07:00
doublespeak Doublespeak: Remove usage of deprecated RSpec #ordered method 2017-09-17 17:01:50 -05:00
independent Adding support to allow_nil option for delegate_method matcher 2018-01-24 02:22:19 -06:00
routing Replace the with_port qualifier on route with port option 2018-01-25 22:31:23 -06:00
util word_wrap: Add ability to indent wrapped text 2015-12-13 20:22:21 -07:00
doublespeak_spec.rb Make Doublespeak specs runnable without Rails 2015-02-28 23:41:28 -07:00