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/support/unit/helpers/message_helpers.rb
Elliot Winkler cd96089a56 belongs_to: Change default req/opt to match global default
In Rails 5, belongs_to associations default to `required: true`. This is
configurable by setting
`ActiveRecord::Base.belongs_to_required_by_default` to true. In new
Rails 5 apps, this is set to true, because the Rails generator will add
an initializer with the following line in it:

  config.active_record.belongs_to_required_by_default = true

However, for Rails apps that have been upgraded from 4 to 5, this
initializer may not be present, and in that case, that setting will not
be set, and `belong_to` associations will not default to `required:
true`.

This means that under Rails 5, our `belong_to` matcher cannot always
default to applying the `required` qualifier; it must abide by the
`belongs_to_required_by_default` setting in doing so.
2018-01-29 00:03:01 -06:00

19 lines
425 B
Ruby

module UnitTests
module MessageHelpers
include Shoulda::Matchers::WordWrap
def self.configure_example_group(example_group)
example_group.include(self)
end
def format_message(message, one_line: false)
stripped_message = message.strip_heredoc.strip
if one_line
stripped_message.tr("\n", " ").squeeze(" ")
else
word_wrap(stripped_message)
end
end
end
end