added tags controller functional test

This commit is contained in:
albert
2011-01-31 02:23:35 -05:00
parent 9837735c93
commit 28b42e791c
6 changed files with 77 additions and 4 deletions

View File

@@ -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

View File

View File

View File

View File

@@ -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

View File

@@ -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