From 28b42e791c7a4499d32de6277a7879dbe81471b4 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 31 Jan 2011 02:23:35 -0500 Subject: [PATCH] added tags controller functional test --- app/controllers/tags_controller.rb | 13 +++++ app/views/tags/edit.html.erb | 0 app/views/tags/index.html.erb | 0 app/views/tags/show.html.erb | 0 db/migrate/20100205162521_create_tags.rb | 1 - test/functional/tags_controller_test.rb | 67 ++++++++++++++++++++++-- 6 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 app/views/tags/edit.html.erb create mode 100644 app/views/tags/index.html.erb create mode 100644 app/views/tags/show.html.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 7f2db9cfe..7a64dd3a2 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,13 +1,26 @@ class TagsController < ApplicationController + before_filter :member_only, :only => [:edit, :update] + respond_to :html, :xml, :json + def edit + @tag = Tag.find(params[:id]) + respond_with(@tag) end def index + @search = Tag.search(params[:search]) + @tags = @search.paginate(:page => params[:page]) + respond_with(@tags) end def show + @tag = Tag.find(params[:id]) + respond_with(@tag) end def update + @tag = Tag.find(params[:id]) + @tag.update_attributes(params[:tag]) + respond_with(@tag) end end diff --git a/app/views/tags/edit.html.erb b/app/views/tags/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tags/show.html.erb b/app/views/tags/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/db/migrate/20100205162521_create_tags.rb b/db/migrate/20100205162521_create_tags.rb index a82e82f43..c3bbe43f8 100644 --- a/db/migrate/20100205162521_create_tags.rb +++ b/db/migrate/20100205162521_create_tags.rb @@ -3,7 +3,6 @@ class CreateTags < ActiveRecord::Migration create_table :tags do |t| t.column :name, :string, :null => false t.column :post_count, :integer, :null => false, :default => 0 - t.column :view_count, :integer, :null => false, :default => 0 t.column :category, :integer, :null => false, :default => 0 t.column :related_tags, :text t.column :related_tags_updated_at, :datetime diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index dcf6b7e57..408abefa4 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -1,8 +1,69 @@ require 'test_helper' class TagsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + context "The tags controller" do + setup do + @user = Factory.create(:user) + CurrentUser.user = @user + CurrentUser.ip_addr = "127.0.0.1" + end + + teardown do + CurrentUser.user = nil + CurrentUser.ip_addr = nil + end + + context "edit action" do + setup do + @tag = Factory.create(:tag, :name => "aaa") + end + + should "render" do + get :edit, {:id => @tag.id}, {:user_id => @user.id} + assert_response :success + end + end + + context "index action" do + setup do + @tag = Factory.create(:tag, :name => "aaa") + end + + should "render" do + get :index + assert_response :success + end + + context "with search parameters" do + should "render" do + get :index, {:search => {:name_equals => "aaa"}} + assert_response :success + end + end + end + + context "show action" do + setup do + @tag = Factory.create(:tag) + end + + should "render" do + get :show, {:id => @tag.id} + assert_response :success + end + end + + context "update action" do + setup do + @tag = Factory.create(:tag) + end + + should "update the tag" do + post :update, {:id => @tag.id, :tag => {:category => "1"}}, {:user_id => @user.id} + assert_redirected_to tag_path(@tag) + @tag.reload + assert_equal(1, @tag.category) + end + end end end