Commit db4e721c

mo khan <mo@mokhan.ca>
2014-10-19 00:29:49
rename creations controller to cakes.
1 parent 12497bf
app/controllers/creations_controller.rb → app/controllers/cakes_controller.rb
@@ -1,4 +1,4 @@
-class CreationsController < ApplicationController
+class CakesController < ApplicationController
   def index
     @creations = AllCakesQuery.new.fetch(params).page(page).per(per_page)
   end
app/controllers/favorites_controller.rb
@@ -7,14 +7,14 @@ class FavoritesController < ApplicationController
   end
 
   def index
-    @creation = Creation.find(params[:creation_id])
+    @creation = Creation.find(params[:cake_id])
     @favorites = @creation.favorites
   end
 
   def create
-    cake = Creation.find(params[:creation_id])
+    cake = Creation.find(params[:cake_id])
     bus.publish(:add_cake_to_favorites, { user_id: current_user.id, cake_id: cake.id })
-    redirect_to cake, notice: "This has been added to your favorites"
+    redirect_to cake_path(cake), notice: "This has been added to your favorites"
   end
 
   private
app/controllers/photos_controller.rb
@@ -1,11 +1,11 @@
 class PhotosController < ApplicationController
   def index
-    @creation = Creation.find(params[:creation_id])
+    @creation = Creation.find(params[:cake_id])
     @photos = @creation.photos
   end
 
   def show
-    @creation = Creation.find(params[:creation_id])
+    @creation = Creation.find(params[:cake_id])
     @photo = @creation.photos.find(params[:id])
   end
 end
app/views/creations/_index.html.erb → app/views/cakes/_index.html.erb
File renamed without changes
app/views/creations/_show.html.erb → app/views/cakes/_show.html.erb
File renamed without changes
app/views/creations/index.html.erb → app/views/cakes/index.html.erb
File renamed without changes
app/views/creations/index.js.erb → app/views/cakes/index.js.erb
File renamed without changes
app/views/creations/show.html.erb → app/views/cakes/show.html.erb
File renamed without changes
app/views/creations/show.js.erb → app/views/cakes/show.js.erb
File renamed without changes
app/views/sitemap/index.xml.erb
@@ -4,7 +4,7 @@
   xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1">
 <% @creations.find_each do |creation| %>
     <url>
-      <loc><%= creation_url(creation) %></loc>
+      <loc><%= cake_url(creation) %></loc>
       <lastmod><%= creation.updated_at.strftime('%Y-%m-%dT%H:%M-06:00') %></lastmod>
       <priority>0.5</priority>
     </url>
config/routes.rb
@@ -15,7 +15,7 @@ Cake::Application.routes.draw do
     end
   end
 
-  resources :creations, only: [:index, :show], path: :cakes do
+  resources :cakes, only: [:index, :show], path: :cakes do
     resources :photos, only: [:index, :show]
     resources :favorites, :only => [:index, :create]
     get 'page/:page', :action => :index, :on => :collection, as: :paginate
spec/controllers/creations_controller_spec.rb → spec/controllers/cakes_controller_spec.rb
@@ -1,6 +1,6 @@
 require 'rails_helper'
 
-describe CreationsController do
+describe CakesController do
   let(:user) { create(:user) }
   let(:cake) { create(:cake, user: user) }
 
spec/controllers/favorites_controller_spec.rb
@@ -3,17 +3,17 @@ require "rails_helper"
 describe FavoritesController do
   context "when logged in" do
     let(:user) { create(:user) }
-    let(:creation) { create(:creation) }
+    let(:cake) { create(:cake) }
 
     before { http_login(user) }
 
     context "when loading all the favorites for a cake" do
-      let(:favorite) { create(:favorite, :creation => creation, :user => user) }
+      let(:favorite) { create(:favorite, creation: cake, user: user) }
 
       before :each do
-        creation.favorites << favorite
-        creation.save!
-        get :index, creation_id: creation.id
+        cake.favorites << favorite
+        cake.save!
+        get :index, cake_id: cake.id
       end
 
       it "should return them all" do
@@ -23,7 +23,7 @@ describe FavoritesController do
 
     context "when adding a cake to your favorites" do
       before :each do
-        post :create, creation_id: creation.id
+        post :create, cake_id: cake.id
       end
 
       it "should add the cake to the logged in users favorites" do
@@ -31,7 +31,7 @@ describe FavoritesController do
       end
 
       it "should redirect to the cake detail page" do
-        expect(response).to redirect_to(creation)
+        expect(response).to redirect_to(cake_path(cake))
       end
 
       it "should include a friendly flash message" do
spec/controllers/photos_controller_spec.rb
@@ -1,19 +1,19 @@
 require 'rails_helper'
 
 describe PhotosController do
-  let(:creation){ create(:creation) }
+  let(:cake){ create(:cake) }
 
   describe "#index" do
     before :each do
-      get :index, creation_id: creation.id
+      get :index, cake_id: cake.id
     end
 
-    it "loads the creation" do
-      assigns(:creation).should == creation
+    it "loads the cake" do
+      expect(assigns(:creation)).to eql(cake)
     end
 
     it "loads the photos" do
-      assigns(:photos).should == creation.photos
+      expect(assigns(:photos)).to match_array(cake.photos)
     end
   end
 
@@ -21,16 +21,16 @@ describe PhotosController do
     let(:photo) { create(:photo) }
 
     before :each do
-      creation.photos.push(photo)
-      get :show, creation_id: creation.id, id: photo.id
+      cake.photos.push(photo)
+      get :show, cake_id: cake.id, id: photo.id
     end
 
     it "loads the cake" do
-      assigns(:creation).should == creation
+      expect(assigns(:creation)).to eql(cake)
     end
 
     it "loads the photo" do
-      assigns(:photo).should == photo
+      expect(assigns(:photo)).to eql(photo)
     end
   end
 end
spec/routing/cakes_routing_spec.rb
@@ -0,0 +1,25 @@
+require "rails_helper"
+
+describe CakesController do
+  describe "routing" do
+    it "is the root of the website" do
+      expect(get: '/').to route_to("cakes#index")
+    end
+
+    it "recognizes and generates #index" do
+      expect(get: 'cakes').to route_to(controller: 'cakes', action: 'index')
+    end
+
+    it "recognizes and generates #show" do
+      expect(get: "/cakes/1").to route_to(controller: "cakes", action: "show", id: "1")
+    end
+
+    it "routes to the newest cakes" do
+      expect(get: '/cakes/newest').to route_to(controller: "cakes", action: "index", sort: 'newest')
+    end
+
+    it "routes to the oldest cakes" do
+      expect(get: '/cakes/oldest').to route_to(controller: "cakes", action: "index", sort: 'oldest')
+    end
+  end
+end
spec/routing/creations_routing_spec.rb
@@ -1,25 +0,0 @@
-require "rails_helper"
-
-describe CreationsController do
-  describe "routing" do
-    it "is the root of the website" do
-      expect(get: '/').to route_to("creations#index")
-    end
-
-    it "recognizes and generates #index" do
-      expect(get: 'cakes').to route_to(controller: 'creations', action: 'index')
-    end
-
-    it "recognizes and generates #show" do
-      expect(get: "/cakes/1").to route_to(controller: "creations", action: "show", id: "1")
-    end
-
-    it "routes to the newest cakes" do
-      expect(get: '/cakes/newest').to route_to(controller: "creations", action: "index", sort: 'newest')
-    end
-
-    it "routes to the oldest cakes" do
-      expect(get: '/cakes/oldest').to route_to(controller: "creations", action: "index", sort: 'oldest')
-    end
-  end
-end