Commit e0ce9c09
Changed files (2)
app
models
spec
models
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