@@ -1,2 +1,18 @@
 class Rating < ActiveRecord::Base
+  belongs_to :account
+  belongs_to :project
+
+  validates :score, numericality: { only_integer: true },
+                    inclusion: { in: [nil, 1, 2, 3, 4, 5] },
+                    allow_nil: true
+
+  after_save :update_project_rating_average
+  after_destroy :update_project_rating_average
+
+  private
+
+  def update_project_rating_average
+    project.editor_account = account
+    project.update_attributes rating_average: project.ratings.average(:score)
+  end
 end
class Rating < ActiveRecord::Base
end

Peter, wouldn't the validates score fail? Although you specified that nil could be a valid value for score, the database on ohloh-qa-db specifies that the field should not be null and that the field should be an integer.Wouldn't a nil value convert to 0? Also, I saw in your test case that 0 is not allowed. How does that work?