Commit 24777e25

mo khan <mo@mokhan.ca>
2013-07-01 20:08:42
add route to display all of my creations
1 parent 28b9710
Changed files (5)
app/controllers/creations_controller.rb
@@ -51,4 +51,8 @@ class CreationsController < ApplicationController
     current_user.creations.find(params[:id]).destroy
     redirect_to(creations_url) 
   end
+
+  def mine
+    @creations = current_user.creations
+  end
 end
app/views/creations/index.html.erb
@@ -60,7 +60,6 @@
               <div class="caption">
                 <h3><a href="<%= url_for creation %>"><%= creation.name %></a> <em><small>by <a href="<%= url_for profile_path(creation.user) %>"> <%= shrink(creation.user.name, 20) %></a></small></em></h3>
                 <p><%= creation.story %></p>
-                <p><a class="btn" href="<%= url_for creation %>">View</a></p>
               </div>
             </div>
           </div>
app/views/creations/mine.html.erb
config/routes.rb
@@ -14,6 +14,7 @@ Cake::Application.routes.draw do
     resources :favorites, :only => [:index, :create]
     resources :comments, :only => [:index, :new, :create]
     get 'page/:page', :action => :index, :on => :collection
+    get 'mine', :action => :mine, :on => :collection
   end
 
   # /profiles
spec/controllers/creations_controller_spec.rb
@@ -112,12 +112,33 @@ describe CreationsController do
       before :each do
         delete :destroy, :id => creation.id
       end
+
       it "destroys the requested creation" do
         user.creations.count.should == 0
       end
+
       it "redirects to the creations list" do
         response.should redirect_to(creations_url)
       end
     end
+
+    describe :mine do
+      let!(:my_creation) { FactoryGirl.create(:creation) }
+      let!(:other_creation) { FactoryGirl.create(:creation) }
+
+      before :each do
+        user.creations << my_creation
+        get :mine
+      end
+
+      it "should return all of my creations" do
+        assigns(:creations).should include(my_creation)
+      end
+
+      it "should not return any other creations" do
+        assigns(:creations).should_not include(other_creation)
+      end
+    end
   end
+
 end