Commit 403967db

mo khan <mo@mokhan.ca>
2013-06-22 14:20:42
create tags index action
1 parent 6ad237f
Changed files (5)
app
config
spec
app/controllers/tags_controller.rb
@@ -1,4 +1,8 @@
 class TagsController < ApplicationController
+  def index
+    @tags = Creation.tag_counts_on(:tags)
+  end
+
   def show
     @tag = params[:id].downcase.gsub(/ /, '-')
     @total_tutorials = Tutorial.tagged_with(@tag).count
app/helpers/tags_helper.rb
@@ -0,0 +1,3 @@
+module TagsHelper
+  include ActsAsTaggableOn::TagsHelper
+end
config/routes.rb
@@ -26,9 +26,10 @@ Cake::Application.routes.draw do
   get 'categories/:slug/page/:page' => "categories#show"
 
   # /tags
-  resources :tags, :only => [:show] do
+  resources :tags, :only => [:index, :show], :path => :t do
     get 'page/:page', :action => :show
   end
+  get 'tags/:id' => 'tags#show'
 
   # /search
   get "search/index"
spec/controllers/tag_controller_spec.rb
@@ -1,6 +1,20 @@
 require "spec_helper"
 
 describe TagsController do
+  describe :index do
+    let(:cake) { FactoryGirl.create(:creation) }
+    let(:user) { FactoryGirl.create(:user) }
+
+    before :each do
+      user.tag(cake, :with => "cake", :on => :tags)
+      get :index
+    end
+
+    it "should load all the tags" do
+      assigns(:tags).count.should == 1
+      assigns(:tags).first.name.should == "cake"
+    end
+  end
   describe :show do
     let(:tag) { "cake" }
     let(:tagged_tutorial) { FactoryGirl.create(:tutorial) }
spec/factories/tag.rb
@@ -0,0 +1,5 @@
+FactoryGirl.define do 
+  factory :tag, :class => "ActsAsTaggableOn::Tag" do
+    name "cake"
+  end
+end