url_validator_spec.rb 919 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UrlValidator, type: :validator do
  4. describe '#validate_each' do
  5. before do
  6. allow(validator).to receive(:compliant?).with(value) { compliant }
  7. validator.validate_each(record, attribute, value)
  8. end
  9. let(:validator) { described_class.new(attributes: [attribute]) }
  10. let(:record) { double(errors: errors) }
  11. let(:errors) { double(add: nil) }
  12. let(:value) { '' }
  13. let(:attribute) { :foo }
  14. context 'unless compliant?' do
  15. let(:compliant) { false }
  16. it 'calls errors.add' do
  17. expect(errors).to have_received(:add).with(attribute, I18n.t('applications.invalid_url'))
  18. end
  19. end
  20. context 'if compliant?' do
  21. let(:compliant) { true }
  22. it 'not calls errors.add' do
  23. expect(errors).not_to have_received(:add).with(attribute, any_args)
  24. end
  25. end
  26. end
  27. end