docbrown/spec/support/initializers/validate_url.rb
rhymes 0a6be8b967
[deploy] Improve some validations (#7335)
* Validations

* Fix specs

* Revert twitter tag change
2020-04-16 18:59:12 +02:00

14 lines
647 B
Ruby

# NOTE: this is copied from https://github.com/perfectline/validates_url/blob/master/lib/validate_url/rspec_matcher.rb
# as the recommended include mechanism doesn't work. Will remove when that's patched correctly
RSpec::Matchers.define :validate_url_of do |attribute|
match do
actual = subject.is_a?(Class) ? subject.new : subject
actual.send(:"#{attribute}=", "htp://invalidurl")
expect(actual).to be_invalid
@expected_message ||= I18n.t("errors.messages.url")
expect(actual.errors.messages[attribute.to_sym]).to include(@expected_message)
end
chain :with_message do |message|
@expected_message = message
end
end