Commit f8b67a31

mo k <mo@mokhan.ca>
2012-09-28 03:48:04
start to fix up the photo controller specs.
1 parent 86d5d8e
Changed files (2)
app/controllers/photos_controller.rb
@@ -4,22 +4,18 @@ class PhotosController < ApplicationController
   before_filter :find_or_build_photo
 
   def create
-    respond_to do |format|
-      if @photo.save
-        format.html { redirect_to(@creation, :notice => 'A new photo was added to the album.') }
-      else
-        flash[:error] = "could not upload photo"
-      end
+    if @photo.save
+      redirect_to(@creation, :notice => 'A new photo was added to the album.') 
+    else
+      flash[:error] = "could not upload photo"
     end
   end
 
   def destroy
-    respond_to do |format|
-      if @photo.destroy
-        format.html { redirect_to(@creation, :notice => 'A new photo was added to the album.') }
-      else
-        flash[:error] = "photo could not be deleted"
-      end
+    if @photo.destroy
+      redirect_to(@creation, :notice => 'A new photo was added to the album.') 
+    else
+      flash[:error] = "photo could not be deleted"
     end
   end
 
@@ -32,5 +28,4 @@ class PhotosController < ApplicationController
   def find_or_build_photo
     @photo = params[:id] ? @creation.photos.find(params[:id]) : @creation.photos.build(params[:photo])
   end
-
 end
spec/controllers/photos_controller_spec.rb
@@ -1,39 +1,38 @@
-require 'spec_helper'
-
 describe PhotosController do
-  include Devise::TestHelpers
-
   let(:user){ FactoryGirl.create(:user) }
   let(:creation){ FactoryGirl.create(:creation) }
 
-  def mock_creation(stubs={})
-    @mock_creation ||= mock_model(Creation, stubs).as_null_object
-  end
-
-  def mock_photo(stubs={})
-    @mock_photo ||= mock_model(Photo, stubs).as_null_object
-  end
-
   before (:each) do
-    request.env['warden'] = mock(Warden, :authenticate => user, :authenticate! => user)
+    user.creations << creation
+    http_login(user)
   end
 
-  describe "GET 'create'" do
+  describe "POST create" do
+    before :each do
+      post :create, :creation_id => creation.id
+    end
     it "returns http success" do
-      user.stub(:creations) { mock_creation }
-      mock_photo.stub(:id) {"1"}
-      mock_photo.stub(:save) {true}
-      mock_creation.stub(:photos) { mock_photo }
-      get :create, :id => "1", :creation_id => "14"
-      # response.should be_success
+      response.should be_success
+    end
+    it "should upload a new photo" do
+      assigns(:photo).should_not be_nil
     end
   end
 
-  describe "GET 'destroy'" do
-    it "returns http success" do
-      # get 'destroy'
-      # response.should be_success
+  describe "DELETE 'destroy'" do
+    let(:photo) { fake }
+    before :each do
+      creation.stub(:photos).and_return(photo)
+      delete :destroy, :creation_id => creation.id, :id => 88
+    end
+    pending "returns http success" do
+      response.should be_success
+    end
+    pending "should destroy the photo" do
+      photo.should have_received(:destroy)
+    end
+    pending "should redirect to the creation" do
+      
     end
   end
-
 end