summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/comments_controller.rb5
-rw-r--r--app/services/comment_on_creation_command.rb1
-rw-r--r--spec/controllers/comments_controller_spec.rb46
-rw-r--r--spec/spec_helper.rb1
4 files changed, 21 insertions, 32 deletions
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 451c5cc9..7fb5e7d3 100644
--- a/app/controllers/comments_controller.rb
+++ b/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
diff --git a/app/services/comment_on_creation_command.rb b/app/services/comment_on_creation_command.rb
index 3217dcbd..4fc765b5 100644
--- a/app/services/comment_on_creation_command.rb
+++ b/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
diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb
index 1ea63211..12972217 100644
--- a/spec/controllers/comments_controller_spec.rb
+++ b/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
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a2696ee2..3d0a86d6 100644
--- a/spec/spec_helper.rb
+++ b/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|