added tags controller functional test
This commit is contained in:
@@ -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
|
||||
|
||||
0
app/views/tags/edit.html.erb
Normal file
0
app/views/tags/edit.html.erb
Normal file
0
app/views/tags/index.html.erb
Normal file
0
app/views/tags/index.html.erb
Normal file
0
app/views/tags/show.html.erb
Normal file
0
app/views/tags/show.html.erb
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user