Commit 4654586d

mo khan <mo@mokhan.ca>
2013-03-02 17:34:21
start to cleanup the comments controller spec.
1 parent acd2aa0
Changed files (3)
spec/controllers/comments_controller_spec.rb
@@ -1,21 +1,50 @@
+require 'spec_helper'
+
 describe CommentsController do
   describe "when signed in" do
     let(:user) { FactoryGirl.create(:user) }
-    before(:each) do
-      http_login(user)
-    end
-    describe "POST create" do
-      let(:creation) { FactoryGirl.create(:creation) }
+
+    context "when logged in" do
       before(:each) do
         http_login(user)
-        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)
+
+      describe "POST create" do
+        let(:creation) { FactoryGirl.create(:creation) }
+
+        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
+
+        it "should create a new comment" do
+          creation.comment_threads.count.should == 1
+        end
+
+        it "should include the person who made the comment" do
+          creation.comment_threads.first.user.should == user
+        end
       end
     end
   end
+
+  context "when not logged in" do
+    let(:creation) { FactoryGirl.create(:creation) }
+
+    before :each do
+      post :create, { :creation_id => creation.id, :comment => { :body => 'hi' } }
+    end
+
+    #need to figure out how to get the devise helpers working
+    xit "should not let you comment" do
+      response.should_not redirect_to(creation)
+    end
+  end
 end
spec/support/devise.rb
@@ -1,8 +1,10 @@
 module DeviseHelper
-  def http_login(user)
-    gateway = fake
-    gateway.stub(:authenticate).and_return(user)
-    gateway.stub(:authenticate!).and_return(user)
-    request.env['warden'] = gateway
+  module Controllers
+    def http_login(user)
+      gateway = fake
+      gateway.stub(:authenticate).and_return(user)
+      gateway.stub(:authenticate!).and_return(user)
+      request.env['warden'] = gateway
+    end
   end
 end
spec/spec_helper.rb
@@ -12,6 +12,6 @@ RSpec.configure do |config|
   config.mock_with :rspec
   config.use_transactional_fixtures = true
   config.infer_base_class_for_anonymous_controllers = false
-  config.include DeviseHelper, :type => :controller
+  config.include DeviseHelper::Controllers, :type => :controller
   config.order = "random"
 end