]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/redaction.rb
Validate user location is sensible
[rails.git] / app / models / redaction.rb
index 43f5b3c7bf70ffb67d8a47d8509c31a9e9fb0a8f..b835864db074b40e7c27cfd8521e0689b96aa979 100644 (file)
@@ -1,10 +1,27 @@
+# == Schema Information
+#
+# Table name: redactions
+#
+#  id                 :integer          not null, primary key
+#  title              :string
+#  description        :text
+#  created_at         :datetime
+#  updated_at         :datetime
+#  user_id            :integer          not null
+#  description_format :enum             default("markdown"), not null
+#
+# Foreign Keys
+#
+#  redactions_user_id_fkey  (user_id => users.id)
+#
+
 ##
 # Redaction represents a record associated with a particular
 # action on the database to hide revisions from the history
-# which are not appropriate to redistribute any more. 
+# which are not appropriate to redistribute any more.
 #
 # The circumstances of the redaction can be recorded in the
-# record's title and description fields, which can be 
+# record's title and description fields, which can be
 # displayed linked from the redacted records.
 #
 class Redaction < ActiveRecord::Base
@@ -14,19 +31,12 @@ class Redaction < ActiveRecord::Base
   has_many :old_ways
   has_many :old_relations
 
-  after_initialize :set_defaults
+  validates :description, :presence => true
+  validates :description_format, :inclusion => { :in => %w[text html markdown] }
 
-  # this method overrides the AR default to provide the rich 
+  # this method overrides the AR default to provide the rich
   # text object for the description field.
   def description
-    RichText.new(read_attribute(:description_format), read_attribute(:description))
-  end
-
-  private
-
-  # set the default format to be markdown, in the absence of
-  # any other setting.
-  def set_defaults
-    self.description_format = "markdown" unless self.attribute_present?(:description_format)
+    RichText.new(self[:description_format], self[:description])
   end
 end