Commit 868cdfb3

mo k <mo@mokhan.ca>
2012-09-28 02:52:04
update the comments controller specs
1 parent 98db5df
app/controllers/comments_controller.rb
@@ -6,8 +6,7 @@ class CommentsController < ApplicationController
   end
 
   def create
-    command_for(CommentOnCreationCommand).run(params)
-    flash[:notice] = "Nice Comment!"
-    redirect_to :controller => 'creations', :action => 'show', :id => params[:creation_id]
+    comment = command_for(CommentOnCreationCommand).run(params)
+    redirect_to comment.commentable, :notice => 'Nice Comment!'
   end
 end
app/services/comment_on_creation_command.rb
@@ -5,5 +5,6 @@ class CommentOnCreationCommand
   def run(params)
     comment = @current_user.comment_on(Creation.find(params[:creation_id]), params[:comment][:body])
     comment.save
+    comment
   end
 end
spec/controllers/comments_controller_spec.rb
@@ -1,32 +1,22 @@
-require_relative '../../app/controllers/comments_controller'
-require 'fakes'
-require 'fakes-rspec'
-
 describe CommentsController do
-  let(:sut) { CommentsController.new }
-
-  describe 'when commenting on a creation' do
-    let(:flash_hash) { {} }
-    let(:payload){ {:creation_id=>88, :comment => {:body => 'blah'}} }
-    let(:command){ fake }
-
-    before(:each) do
-      sut.stub(:params).and_return(payload)
-      sut.stub(:flash).and_return(flash_hash)
-      sut.stub(:redirect_to).and_return(nil)
-      sut.stub(:command_for).with(CommentOnCreationCommand).and_return(command)
-
-      sut.create
-    end
-
-    it "should save the new comment" do
-      command.should have_received(:run, payload)
-    end
-    it "should display a message indicated that the comment was saved" do
-      flash_hash[:notice].should_not be_nil
-    end
-    it "should redirect to the creation#show page" do
-     
+  describe "POST create" do
+    describe "when signed in" do
+      let(:user) { FactoryGirl.create(:user) }
+      let(:creation) { FactoryGirl.create(:creation) }
+      before :each do
+        http_login(user)
+      end
+      describe 'when commenting on a creation' do
+        before(:each) do
+          post :create, {:creation_id => creation.id, :comment => {:body => 'blah'}}
+        end
+        it "should display a message indicated that the comment was saved" do
+          flash[:notice].should_not be_nil
+        end
+        it "should redirect to the creation#show page" do
+          response.should redirect_to(creation)
+        end
+      end
     end
   end
 end
spec/spec_helper.rb
@@ -6,7 +6,6 @@ Spork.prefork do
   require File.expand_path("../../config/environment", __FILE__)
   require 'rspec/rails'
   require 'capybara/rspec'
-    
 
   Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
   RSpec.configure do |config|