thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_record
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
..
association_matchers Improve messaging of .required and .optional 2019-02-14 17:48:26 -07:00
uniqueness Documentation updates 2014-12-25 01:13:30 -05:00
accept_nested_attributes_for_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
association_matcher.rb Add without_presence_validation q to belong_to 2019-02-14 17:48:26 -07:00
association_matchers.rb Extract examples in README to inline documentation 2014-06-20 16:41:27 -06:00
define_enum_for_matcher.rb Add with_prefix and with_suffix to define_enum_for 2018-01-28 00:47:56 -06:00
have_db_column_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
have_db_index_matcher.rb Fix typo (#1119) 2018-08-10 14:36:12 +01:00
have_readonly_attribute_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
have_secure_token_matcher.rb Add matcher for has_secure_token 2017-10-15 21:07:58 -04:00
serialize_matcher.rb Update RSpec test style across docs 2016-06-15 18:02:07 -06:00
uniqueness.rb Move uniqueness validation to ActiveRecord module 2014-12-13 17:53:16 -05:00
validate_uniqueness_of_matcher.rb Fixes uniqueness validator syntax in documentation (#1172) 2019-02-03 22:58:05 -07:00