class WikiMotion < ActiveRecord::Base
  self.table_name = "pw_dyn_wiki_motion"

  belongs_to :division
  belongs_to :user

  validates :title, presence: true

  attr_accessor :title, :description

  before_save :set_text_body, unless: :text_body

  private

  def set_text_body
    self.text_body = <<-RECORD
--- DIVISION TITLE ---

#{title}

--- MOTION EFFECT ---

#{description}

--- COMMENTS AND NOTES ---

(put thoughts and notes for other researchers here)
    RECORD
  end
end

class WikiMotion < ActiveRecord::Base
  self.table_name = "pw_dyn_wiki_motion"

  belongs_to :division
  belongs_to :user

  validates :title, presence: true

  attr_accessor :title, :description

  before_save :set_text_body, unless: :text_body

  # Strip timezone as it's stored in the DB as local time
  def edit_date
    Time.parse(read_attribute(:edit_date).strftime('%F %T'))
  end

  # FIXME: Stop this nonsense of storing local times in the DB to match PHP
  def edit_date=(date)
    write_attribute(:edit_date, date.strftime('%F %T'))
  end

  private

  def set_text_body
    self.text_body = <<-RECORD
--- DIVISION TITLE ---

#{title}

--- MOTION EFFECT ---

#{description}

--- COMMENTS AND NOTES ---

(put thoughts and notes for other researchers here)
    RECORD
  end
end

Store the edit date in local time to match the PHP app
Store the edit date in local time to match the PHP app
