added alias functional test
This commit is contained in:
@@ -1,22 +1,43 @@
|
|||||||
class TagAliasesController < ApplicationController
|
class TagAliasesController < ApplicationController
|
||||||
|
before_filter :admin_only, :only => [:new, :edit, :create, :update, :destroy]
|
||||||
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@tag_alias = TagAlias.new
|
||||||
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@search = TagAlias.search(params[:search])
|
||||||
|
@tag_aliases = @search.paginate(:page => params[:page])
|
||||||
|
respond_with(@tag_aliases)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@tag_alias = TagAlias.create(params[:tag_alias])
|
||||||
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
|
@tag_alias.update_attributes(params[:tag_alias])
|
||||||
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
|
@tag_alias.destroy
|
||||||
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_cache
|
def cache
|
||||||
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
|
@tag_alias.clear_cache
|
||||||
|
render :nothing => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
0
app/views/tag_aliases/edit.html.erb
Normal file
0
app/views/tag_aliases/edit.html.erb
Normal file
0
app/views/tag_aliases/index.html.erb
Normal file
0
app/views/tag_aliases/index.html.erb
Normal file
0
app/views/tag_aliases/new.html.erb
Normal file
0
app/views/tag_aliases/new.html.erb
Normal file
@@ -1,2 +1,4 @@
|
|||||||
Factory.define(:tag_alias) do |f|
|
Factory.define(:tag_alias) do |f|
|
||||||
|
f.antecedent_name "aaa"
|
||||||
|
f.consequent_name "bbb"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,87 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TagAliasesControllerTest < ActionController::TestCase
|
class TagAliasesControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "The tag aliases controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
MEMCACHE.flush_all
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
setup do
|
||||||
|
@tag_alias = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :creator => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "list all tag aliass" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "list all tag_aliass (with search)" do
|
||||||
|
get :index, {:search => {:antecedent_name_matches => "aaa"}}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "edit action" do
|
||||||
|
setup do
|
||||||
|
@tag_alias = Factory.create(:tag_alias, :creator => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
get :edit, {:id => @tag_alias.id}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "create a tag alias" do
|
||||||
|
assert_difference("TagAlias.count", 1) do
|
||||||
|
post :create, {:tag_alias => {:antecedent_name => "xxx", :consequent_name => "yyy"}}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
setup do
|
||||||
|
@tag_alias = Factory.create(:tag_alias, :creator => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "update a tag_alias" do
|
||||||
|
post :update, {:id => @tag_alias.id, :tag_alias => {:antecedent_name => "zzz"}}, {:user_id => @user.id}
|
||||||
|
@tag_alias.reload
|
||||||
|
assert_equal("zzz", @tag_alias.antecedent_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
setup do
|
||||||
|
@tag_alias = Factory.create(:tag_alias, :creator => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "destroy a tag_alias" do
|
||||||
|
assert_difference("TagAlias.count", -1) do
|
||||||
|
post :destroy, {:id => @tag_alias.id}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy_cache action" do
|
||||||
|
setup do
|
||||||
|
@tag_alias = Factory.create(:tag_alias, :antecedent_name => "aaa", :creator => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "reset the cache" do
|
||||||
|
post :cache, {:id => @tag_alias.id}, {:user_id => @user.id}
|
||||||
|
assert_nil(Cache.get("ta:aaa"))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user