• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AgileVentures / WebsiteOne / #244

13 Dec 2022 07:22PM UTC coverage: 70.485% (-5.3%) from 75.768%
#244

push

web-flow
Merge pull request #3814 from mattlindsey/3805_testing_updates

Replace jasmine gem and phantomjs

800 of 1135 relevant lines covered (70.48%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.44
/lib/validators/uri_validator.rb
1
# frozen_string_literal: true
2

3
require 'addressable/uri'
1✔
4
class UriValidator < ActiveModel::EachValidator
1✔
5
  def validate_each(record, attribute, value)
1✔
6
    uri = parse_uri(value)
×
7
    if !uri
×
8
      record.errors.add(attribute, generic_failure_message)
×
9
    elsif !allowed_protocols.include?(uri.scheme)
×
10
      record.errors.add(attribute, "must begin with #{allowed_protocols_humanized}")
×
11
    end
12
  end
13

14
  private
1✔
15

16
  def generic_failure_message
1✔
17
    options[:message] || 'is an invalid URL'
×
18
  end
19

20
  def allowed_protocols_humanized
1✔
21
    allowed_protocols.to_sentence(two_words_connector: ' or ')
×
22
  end
23

24
  def allowed_protocols
1✔
25
    @allowed_protocols ||= Array((options[:allowed_protocols] || %w(http https)))
×
26
  end
27

28
  def parse_uri(value)
1✔
29
    uri = Addressable::URI.parse(value)
×
30
    uri.scheme && uri.host && uri
×
31
  rescue URI::InvalidURIError, Addressable::URI::InvalidURIError, TypeError
32
  end
33
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc