Commit e0ce9c09

mo khan <mo@mokhan.ca>
2014-01-19 05:54:37
create a new activity when a comment is created.
1 parent a8ccb34
Changed files (2)
app
spec
app/models/comment.rb
@@ -1,4 +1,12 @@
 class Comment < ActiveRecord::Base
   belongs_to :user
   belongs_to :creation
+  has_many :activities, as: :subject
+  after_create :create_activity
+
+  private
+
+  def create_activity
+    Activity.create(user: user, subject: self)
+  end
 end
spec/models/comment_spec.rb
@@ -0,0 +1,13 @@
+require "spec_helper"
+
+describe Comment do
+  describe "#create" do
+    let(:creation) { create(:creation) }
+    let(:user) { creation.user }
+
+    it "creates a new activity" do
+      comment = Comment.create(user: user, creation: creation)
+      comment.activities.count.should == 1
+    end
+  end
+end