class Url < ActiveRecord::Base
  validates_presence_of :viewport_width,
                        :address,
                        :name

  validates_format_of     :address, with: %r[https?://.+]
  validates_uniqueness_of :address

  has_many :snapshots
  has_one  :baseline

  default_scope { order(:name) }

  def to_param
    [id, slugify(name)].join('-')
  end

  private

  # @param [String] string to slugify
  # @return [String] slugified version of str
  def slugify(str)
    str.gsub(/['’]/, '').parameterize
  end
end

class Url < ActiveRecord::Base
  validates_presence_of :viewport_width,
                        :address,
                        :name

  validates_format_of     :address, with: %r[\Ahttps?://.+]
  validates_uniqueness_of :address

  has_many :snapshots
  has_one  :baseline

  default_scope { order(:name) }

  def to_param
    [id, slugify(name)].join('-')
  end

  private

  # @param [String] string to slugify
  # @return [String] slugified version of str
  def slugify(str)
    str.gsub(/['’]/, '').parameterize
  end
end

Improve Url address format validation
Improve Url address format validation

By anchoring our regex at the beginning of the string, we prevent
possibly incorrect addresses from slipping through the cracks.

Change-Id: Ied867410dcb37d99f0a7c5fe3d435b7b26bbded8
