Commit 9b1a4822

mo k <mo@mokhan.ca>
2012-06-10 17:53:52
refactory comment command to use user model to create comment.
1 parent f4ffca5
app/services/comment_on_creation_command.rb
@@ -3,8 +3,8 @@ class CommentOnCreationCommand
     @current_user = user
   end
   def run(params)
-    creation = Creation.find(params[:creation_id])
-    comment = Comment.build_from(creation, @current_user.id, params[:comment][:body])
+    comment = @current_user.comment_on(Creation.find(params[:creation_id]), params[:comment][:body])
+    #comment = Comment.build_from(creation, @current_user.id, params[:comment][:body])
     comment.save
   end
 end
spec/services/command_on_creation_command_spec.rb
@@ -0,0 +1,20 @@
+describe CommentOnCreationCommand do
+  let(:sut) { CommentOnCreationCommand.new(user) }
+  let(:user) { fake }
+  describe "when run" do
+    let(:creation) { fake }
+    let(:comment) { fake }
+    it "should add the new comment to the creation" do
+      user.should have_received(:comment_on, creation, "wow")
+    end
+    it "should save the comment" do
+      comment.should have_received(:save)
+    end
+    before(:each) do
+      params = {:creation_id => 8, :comment => { :body => "wow" }}
+      Creation.stub(:find).with(8).and_return(creation)
+      user.stub(:comment_on).with(creation, "wow").and_return(comment)
+      sut.run(params)
+    end
+  end
+end