class Lesson < ActiveRecord::Base
  attr_accessible :background, :free, :title, :video

  validates :title,      :presence => { :message => "for lesson can't be blank" }
  validates :background, :presence => { :message => "for lesson can't be blank" }

  validate  :free_is_valid
  validate  :url_exists

  belongs_to :course

  def club
    course.club
  end

  def user
    club.user
  end

  def assign_defaults
    self.title      = "Lesson #{(course.lessons.count + 1)} - #{Settings.lessons[:default_title]}"
    self.background = Settings.lessons[:default_background]
    self.free       = Settings.lessons[:default_free]
  end

  private

  def url_exists
    unless video.blank?
      errors.add(:base, "URL is not reachable or malformed - please check your video URL") unless VideoManipulator.validate_url(video)
    end
  end

  def free_is_valid
    unless free.to_s =~ /(true|false)/
      errors.add(:base, "Free must be either true or false")
    end
  end
end

class Lesson < ActiveRecord::Base
  attr_accessible :background, :free, :title, :video

  validates :title,      :presence => { :message => "for lesson can't be blank" }
  validates :background, :presence => { :message => "for lesson can't be blank" }

  validate  :free_is_valid
  validate  :url_exists

  belongs_to :course

  def club
    course.club
  end

  def user
    club.user
  end

  def assign_defaults
    self.title      = "Lesson #{(course.lessons.count + 1)} - #{Settings.lessons[:default_title]}"
    self.background = Settings.lessons[:default_background]
    self.free       = Settings.lessons[:default_free]
  end

  private

  def url_exists
    unless video.blank?
      errors.add(:base, "URL is not reachable or malformed - please check your video URL") unless VideoManipulator.validate_url(video)
    end
  end

  def free_is_valid
    unless free.to_s =~ /(true|false)/
      errors.add(:base, "Free for lesson must be either true or false")
    end
  end
end

Update Text for Lesson free Attribute Error
Update Text for Lesson free Attribute Error

Update the message for the Lesson errors associated with the free
attribute not being a valid value.
