From 0bb3e75fb6aff7573fd43129292a90aa1af6e867 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 12 Apr 2012 14:47:53 +0200 Subject: [PATCH] No need for instance variables in CommentsController#create --- app/controllers/api/comments_controller.rb | 12 ++++++------ spec/controllers/api/comments_controller_spec.rb | 12 +----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/comments_controller.rb b/app/controllers/api/comments_controller.rb index c05d8ae..15cf163 100644 --- a/app/controllers/api/comments_controller.rb +++ b/app/controllers/api/comments_controller.rb @@ -9,14 +9,14 @@ class Api::CommentsController < ApplicationController end def create - @comment = Comment.new(params[:comment]) - @comment.asciicast = @asciicast - @comment.user = current_user + comment = Comment.new(params[:comment]) + comment.asciicast = @asciicast + comment.user = current_user - @comment.save + comment.save - comment = CommentDecorator.new(@comment) - respond_with comment, :location => api_comment_url(@comment) + decorated_comment = CommentDecorator.new(comment) + respond_with decorated_comment, :location => api_comment_url(comment) end def destroy diff --git a/spec/controllers/api/comments_controller_spec.rb b/spec/controllers/api/comments_controller_spec.rb index b4be62c..06dd221 100644 --- a/spec/controllers/api/comments_controller_spec.rb +++ b/spec/controllers/api/comments_controller_spec.rb @@ -26,17 +26,7 @@ describe Api::CommentsController do Comment.any_instance.should_receive(:save).and_return(true) end - it "assigns current_user" do - dispatch - assigns(:comment).user.should_not be_blank - end - - it "assigns asciicast" do - dispatch - assigns(:comment).asciicast.should_not be_blank - end - - it "assigns asciicast" do + it "response status should be 201" do dispatch response.status.should == 201 end