Commit 24249c3d

mo khan <mo@mokhan.ca>
2013-05-10 23:26:04
start to add specs for favorites#create
1 parent e36d708
Changed files (2)
app/controllers/favorites_controller.rb
@@ -9,7 +9,7 @@ class FavoritesController < ApplicationController
 
   # POST /favorites
   def create
-    if( current_user.owns @creation )
+    if current_user.owns @creation
       redirect_to @creation, :notice => "You can't favorite your own stuff"
       return
     end
spec/controllers/favorites_controller_spec.rb
@@ -3,11 +3,11 @@ require "spec_helper"
 describe FavoritesController do
   context "when logged in" do
     let(:user) { FactoryGirl.create(:user) }
+    let(:creation) { FactoryGirl.create(:creation) }
 
     before { http_login(user) }
 
-    context "when loading all the favorites for a creation" do
-      let(:creation) { FactoryGirl.create(:creation) }
+    context "when loading all the favorites for a cake" do
       let(:favorite) { FactoryGirl.create(:favorite, :creation => creation, :user => user) }
 
       before :each do
@@ -20,6 +20,24 @@ describe FavoritesController do
         assigns(:favorites).should include favorite
       end
     end
+
+    context "when adding a cake to your favorites" do
+      before :each do
+        post :create, :creation_id => creation.id
+      end
+
+      it "should add the cake to the logged in users favorites" do
+        user.reload.favorites.count == 1
+      end
+
+      it "should redirect to the cake detail page" do
+        response.should redirect_to(creation)
+      end
+
+      it "should include a friendly flash message" do
+        flash[:notice].should_not be_nil
+      end
+    end
   end
 
 end