Set up the feed_item model
[feedcatcher.git] / app / models / feed_item.rb
index d875a8aa3bac6531e0c9d42dcfee0c2c1e44ff0c..db0613da3827753d0ae08c5a77984926a8463974 100644 (file)
@@ -1,2 +1,22 @@
 class FeedItem < ActiveRecord::Base
+  validates_presence_of :feed_name, :title, :description
+  validates_uniqueness_of :title, :scope => :feed_name
+  validate :feed_name_must_be_legal
+
+  def FeedItem.valid_feed_name?(feed_name)
+    Rack::Utils::escape(feed_name) == feed_name and
+      Rack::Utils::unescape(feed_name) == feed_name and
+      feed_name != 'index' and
+      feed_name != 'show' and
+      feed_name != 'update' and
+      feed_name != 'action'
+  end
+
+  private
+
+  def feed_name_must_be_legal
+    unless FeedItem.valid_feed_name?(feed_name)
+      errors.add(:feed_name, 'is invalid')
+    end
+  end
 end