Commit 49cfbc73

mo k <mo@mokhan.ca>
2011-06-22 03:08:15
fix creations controller specs.
1 parent 94ea583
Changed files (1)
spec/controllers/creations_controller_spec.rb
@@ -5,11 +5,20 @@ require 'spec_helper'
 # was generated by the Rails when you ran the scaffold generator.
 
 describe CreationsController do
+  include Devise::TestHelpers
+
+  def mock_user(stubs={})
+    @mock_user ||= mock_model(User, stubs).as_null_object
+  end
 
   def mock_creation(stubs={})
     @mock_creation ||= mock_model(Creation, stubs).as_null_object
   end
 
+  before (:each) do
+    request.env['warden'] = mock(Warden, :authenticate => mock_user, :authenticate! => mock_user)
+  end
+
   describe "GET index" do
     it "assigns all creations as @creations" do
       Creation.stub(:all) { [mock_creation] }
@@ -36,7 +45,8 @@ describe CreationsController do
 
   describe "GET edit" do
     it "assigns the requested creation as @creation" do
-      Creation.stub(:find).with("37") { mock_creation }
+      # Creation.stub(:find).with("37") { mock_creation }
+      mock_user.stub(:creations){ mock_creation }
       get :edit, :id => "37"
       assigns(:creation).should be(mock_creation)
     end
@@ -45,13 +55,15 @@ describe CreationsController do
   describe "POST create" do
     describe "with valid params" do
       it "assigns a newly created creation as @creation" do
-        Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => true) }
+        # Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => true) }
+        mock_user.stub(:creations){ mock_creation(:save => true) }
         post :create, :creation => {'these' => 'params'}
         assigns(:creation).should be(mock_creation)
       end
 
       it "redirects to the created creation" do
-        Creation.stub(:new) { mock_creation(:save => true) }
+        # Creation.stub(:new) { mock_creation(:save => true) }
+        mock_user.stub(:creations){ mock_creation(:save => true) }
         post :create, :creation => {}
         response.should redirect_to(creation_url(mock_creation))
       end
@@ -59,13 +71,15 @@ describe CreationsController do
 
     describe "with invalid params" do
       it "assigns a newly created but unsaved creation as @creation" do
-        Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => false) }
+        # Creation.stub(:new).with({'these' => 'params'}) { mock_creation(:save => false) }
+        mock_user.stub(:creations){ mock_creation(:save => false) }
         post :create, :creation => {'these' => 'params'}
         assigns(:creation).should be(mock_creation)
       end
 
       it "re-renders the 'new' template" do
-        Creation.stub(:new) { mock_creation(:save => false) }
+        # Creation.stub(:new) { mock_creation(:save => false) }
+        mock_user.stub(:creations){ mock_creation(:save => false) }
         post :create, :creation => {}
         response.should render_template("new")
       end
@@ -75,19 +89,22 @@ describe CreationsController do
   describe "PUT update" do
     describe "with valid params" do
       it "updates the requested creation" do
-        Creation.stub(:find).with("37") { mock_creation }
+        # Creation.stub(:find).with("37") { mock_creation }
+        mock_user.stub(:creations){ mock_creation }
         mock_creation.should_receive(:update_attributes).with({'these' => 'params'})
         put :update, :id => "37", :creation => {'these' => 'params'}
       end
 
       it "assigns the requested creation as @creation" do
-        Creation.stub(:find) { mock_creation(:update_attributes => true) }
+        # Creation.stub(:find) { mock_creation(:update_attributes => true) }
+        mock_user.stub(:creations){ mock_creation(:update_attributes => true) }
         put :update, :id => "1"
         assigns(:creation).should be(mock_creation)
       end
 
       it "redirects to the creation" do
-        Creation.stub(:find) { mock_creation(:update_attributes => true) }
+        # Creation.stub(:find) { mock_creation(:update_attributes => true) }
+        mock_user.stub(:creations){ mock_creation(:update_attributes => true) }
         put :update, :id => "1"
         response.should redirect_to(creation_url(mock_creation))
       end
@@ -95,13 +112,15 @@ describe CreationsController do
 
     describe "with invalid params" do
       it "assigns the creation as @creation" do
-        Creation.stub(:find) { mock_creation(:update_attributes => false) }
+        mock_user.stub(:creations){ mock_creation(:update_attributes => false) }
+        # Creation.stub(:find) { mock_creation(:update_attributes => false) }
         put :update, :id => "1"
         assigns(:creation).should be(mock_creation)
       end
 
       it "re-renders the 'edit' template" do
-        Creation.stub(:find) { mock_creation(:update_attributes => false) }
+        mock_user.stub(:creations){ mock_creation(:update_attributes => false) }
+        # Creation.stub(:find) { mock_creation(:update_attributes => false) }
         put :update, :id => "1"
         response.should render_template("edit")
       end
@@ -110,7 +129,8 @@ describe CreationsController do
 
   describe "DELETE destroy" do
     it "destroys the requested creation" do
-      Creation.stub(:find).with("37") { mock_creation }
+#      Creation.stub(:find).with("37") { mock_creation }
+      mock_user.stub(:creations){ mock_creation }
       mock_creation.should_receive(:destroy)
       delete :destroy, :id => "37"
     end