Commit 6a07f43e
Changed files (8)
app
controllers
views
categories
config
spec
controllers
app/controllers/categories_controller.rb
@@ -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
app/views/categories/_show.html.erb
@@ -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>
app/views/categories/show.html.erb
@@ -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>
app/views/categories/show.js.erb
@@ -1,3 +0,0 @@
-$('#more-button-row').remove();
-$('#pagination-row').remove();
-$('#bakery').append('<%= j render partial: 'show' %>');
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
spec/controllers/categories_controller_spec.rb
@@ -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
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
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