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

AgileVentures / WebsiteOne / #241

03 Jan 2023 01:44PM UTC coverage: 61.538% (-1.6%) from 63.166%
#241

push

web-flow
Updates for relaunch

536 of 871 relevant lines covered (61.54%)

0.63 hits per line

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

42.86
/lib/validators/image_url_validator.rb
1
# frozen_string_literal: true
2

3
class ImageUrlValidator < ActiveModel::Validator
1✔
4
  IMAGE_HOST_WHITELIST = %w(bluemelon.com deviantart.com facebook.com
1✔
5
                            flickr.com freeimagehosting.net imagebam.com imageshack.com
6
                            imagevenue.com imgur.com instagram postimage.org photobucket.com
7
                            picasa.com shutterfly.com slickpic.com snapfish.com smugmug.com
8
                            tinypic.com twitpic.com webshots.com weheartit.com zenfolio.com).freeze
9

10
  def validate(record)
1✔
11
    if record.image_url.present?
×
12
      if invalid_format?(record.image_url)
×
13
        record.errors.add(:image_url, 'Invalid format. Image must be png, jpg, or jpeg.')
×
14
      end
15

16
      unless is_image_host_whitelisted?(record.image_url)
×
17
        record.errors.add(:image_url, 'Invalid image url. Image provider not found in provider whitelist.')
×
18
      end
19
    end
20
  end
21

22
  private
1✔
23

24
  def invalid_format?(url)
1✔
25
    validation_regex = /\.(png|jpg|jpeg)$/i
×
26
    validation_regex.match(url).nil?
×
27
  end
28

29
  def is_image_host_whitelisted?(url)
1✔
30
    IMAGE_HOST_WHITELIST.any? { |whitelist_item| url.match /#{Regexp.escape(whitelist_item)}/ }
×
31
  end
32
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