diff options
| author | mo khan <mo@mokhan.ca> | 2014-10-18 19:16:37 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-10-18 19:16:37 -0600 |
| commit | 6a07f43e2f8b2ff287ee70bccf879219b5b09cd8 (patch) | |
| tree | 8895176ddc364cf35784f92830b369cadadd1d86 | |
| parent | d11af17e3cbc3622fae5f7cec5c31a2f44ebdf41 (diff) | |
route categories to the cakes controller and remove old categories controller.
| -rw-r--r-- | app/controllers/categories_controller.rb | 10 | ||||
| -rw-r--r-- | app/views/categories/_show.html.erb | 25 | ||||
| -rw-r--r-- | app/views/categories/show.html.erb | 8 | ||||
| -rw-r--r-- | app/views/categories/show.js.erb | 3 | ||||
| -rw-r--r-- | config/routes.rb | 9 | ||||
| -rw-r--r-- | spec/controllers/categories_controller_spec.rb | 36 | ||||
| -rw-r--r-- | spec/routing/cakes_routing_spec.rb | 32 | ||||
| -rw-r--r-- | spec/routing/categories_routing_spec.rb | 13 |
8 files changed, 24 insertions, 112 deletions
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb deleted file mode 100644 index b696750a..00000000 --- a/app/controllers/categories_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CategoriesController < ApplicationController - def show - @category = Category.find_by_slug(params[:id].downcase) - if @category - @creations = @category.creations.includes(:user, :photos).page(params[:page]).per(12) - else - redirect_to creation_tag_path(params[:id].downcase), status: :moved_permanently - end - end -end diff --git a/app/views/categories/_show.html.erb b/app/views/categories/_show.html.erb deleted file mode 100644 index b2818633..00000000 --- a/app/views/categories/_show.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<div class="row-fluid"> - <% @creations.each_slice(6).each do |batch| %> - <ul class='thumbnails'> - <% batch.each do |creation| %> - <% cache creation do %> - <li class="span2"> - <div class="thumbnail"> - <%= link_to creation do %> - <%= image_tag creation.primary_image.url_for(:thumb) %> - <% end %> - <div class="caption"> - <h4><%= link_to shrink(creation.name, 12), creation %></h4> - <p><%= link_to shrink(creation.user.name, 20), profile_path(creation.user) %></p> - <p><small><%= time_ago_in_words(creation.created_at) %> ago.</small></p> - </div> - </div> - </li> - <% end %> - <% end %> - </ul> - <% end %> -</div> -<div id='more-button-row' class="row-fluid"> - <%= link_to_next_page @creations, 'More...', params: { cache: false }, remote: true, class: 'more-button hidden', data: { disable_with: 'loading...' } %> -</div> diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb deleted file mode 100644 index ffa8db15..00000000 --- a/app/views/categories/show.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% provide(:title, "#{@category.name} Cakes") -%> -<div id="bakery"> - <%= render partial: "show" %> -</div> - -<div id='pagination-row' class="row-fluid"> - <%= render "shared/paging", items: @creations %> -</div> diff --git a/app/views/categories/show.js.erb b/app/views/categories/show.js.erb deleted file mode 100644 index 5410fd59..00000000 --- a/app/views/categories/show.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -$('#more-button-row').remove(); -$('#pagination-row').remove(); -$('#bakery').append('<%= j render partial: 'show' %>'); diff --git a/config/routes.rb b/config/routes.rb index bd22f5fb..30372d18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,8 @@ Cake::Application.routes.draw do get :oldest, action: 'index', sort: 'oldest' end end - + get '/categories/:category', to: 'cakes#index', as: :category + get '/categories/:category/page/:page', to: 'cakes#index' get '/creations' => redirect('/cakes') get 'creations/:id', to: redirect('/cakes/%{id}') get 'creations/page/:page', to: redirect('/cakes/page/%{page}') @@ -33,12 +34,6 @@ Cake::Application.routes.draw do get 'page/:page', :action => :index, :on => :collection, as: :paginate end - resources :categories, only: [:show] do - member do - get 'page/:page', action: :show, as: :paginate - end - end - # /tags resources :creation_tags, :only => [:index, :show], :path => :t do member do diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb deleted file mode 100644 index 67b5d041..00000000 --- a/spec/controllers/categories_controller_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rails_helper' - -describe CategoriesController do - let(:creation) { create(:creation) } - let(:category) { create(:category, :creations => [creation]) } - - describe "GET show" do - context "when there is a category that matches the slug" do - context "when there are creations in the category" do - before { get :show, id: category.slug } - - it "should return the creations in the category" do - assigns(:creations).should include(creation) - end - - it "should return the category" do - assigns(:category).should == category - end - end - - context "when there are no creations in the category" do - let(:other_category) { create(:category, slug: 'booooo') } - - before { get :show, id: other_category.to_param } - - it "should return zero creations" do - assigns(:creations).should be_empty - end - - it "should return the category" do - assigns(:category).should eq(other_category) - end - end - end - end -end diff --git a/spec/routing/cakes_routing_spec.rb b/spec/routing/cakes_routing_spec.rb index bcb34e00..d3c07c83 100644 --- a/spec/routing/cakes_routing_spec.rb +++ b/spec/routing/cakes_routing_spec.rb @@ -1,25 +1,23 @@ 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 +describe "/cakes" 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 #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 "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 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 + it "routes to the oldest cakes" do + expect(get: '/cakes/oldest').to route_to(controller: "cakes", action: "index", sort: 'oldest') end end diff --git a/spec/routing/categories_routing_spec.rb b/spec/routing/categories_routing_spec.rb index e7382f17..97920736 100644 --- a/spec/routing/categories_routing_spec.rb +++ b/spec/routing/categories_routing_spec.rb @@ -1,10 +1,11 @@ require "rails_helper" -describe CategoriesController do - describe "routing" do - it "routes to #show" do - expect(get: "/categories/fondant").to route_to(id: "fondant", controller: "categories", action: "show") - end +describe '/categories' do + it "routes to #show" do + expect(get: "/categories/fondant").to route_to(category: "fondant", controller: "cakes", action: "index") end -end + it '/categories/cookies/page/2' do + expect(get: "/categories/fondant/page/2").to route_to(category: "fondant", controller: "cakes", action: "index", page: '2') + end +end |
