<commit_before>require 'state_machine'

class TravelAdviceEdition
  include Mongoid::Document
  include Mongoid::Timestamps
  include Parted

  field :country_slug,         type: String
  field :version_number,       type: Integer
  field :state,                type: String,    default: "draft"

  index [[:country_slug, Mongo::ASCENDING], [:version_number, Mongo::DESCENDING]], :unique => true

  before_validation :populate_version_number, :on => :create

  validates_presence_of :country_slug
  validate :state_for_slug_unique
  validates :version_number, :presence => true, :uniqueness => { :scope => :country_slug }

  scope :published, where(:state => "published")

  state_machine initial: :draft do
    event :publish do
      transition draft: :published 
    end

    event :archive do
      transition all => :archived, :unless => :archived?
    end
  end

  def build_clone
    new_edition = self.class.new(:country_slug => self.country_slug)<commit_msg>Add GOVSPEAK_FIELDS and SafeHtml validation to TravelAdviceEdition<commit_after>require 'state_machine'

class TravelAdviceEdition
  include Mongoid::Document
  include Mongoid::Timestamps
  include Parted

  field :country_slug,         type: String
  field :version_number,       type: Integer
  field :state,                type: String,    default: "draft"

  index [[:country_slug, Mongo::ASCENDING], [:version_number, Mongo::DESCENDING]], :unique => true

  GOVSPEAK_FIELDS = []

  before_validation :populate_version_number, :on => :create

  validates_presence_of :country_slug
  validate :state_for_slug_unique
  validates :version_number, :presence => true, :uniqueness => { :scope => :country_slug }
  validates_with SafeHtml

  scope :published, where(:state => "published")

  state_machine initial: :draft do
    event :publish do
      transition draft: :published 
    end

    event :archive do
      transition all => :archived, :unless => :archived?
    end
  end

  def build_clone
    new_edition = self.class.new(:country_slug => self.country_slug)
{'fraction_non_alphanumeric': 0.09671084928816888, 'fraction_numerical': 0.0, 'mean_word_length': 4.0320987654320986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '505192', 'n_tokens_mistral': 630, 'n_tokens_neox': 615, 'n_words': 160}