From d6f7ccd7efce5232706c8d09fed3de0ee205c56f Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 29 Jan 2011 04:17:45 -0500 Subject: [PATCH] added alias functional test --- app/controllers/tag_aliases_controller.rb | 23 ++++- app/views/tag_aliases/edit.html.erb | 0 app/views/tag_aliases/index.html.erb | 0 app/views/tag_aliases/new.html.erb | 0 test/factories/tag_alias.rb | 2 + .../functional/tag_aliases_controller_test.rb | 85 ++++++++++++++++++- 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 app/views/tag_aliases/edit.html.erb create mode 100644 app/views/tag_aliases/index.html.erb create mode 100644 app/views/tag_aliases/new.html.erb diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 3c384b711..10f297bfe 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -1,22 +1,43 @@ class TagAliasesController < ApplicationController + before_filter :admin_only, :only => [:new, :edit, :create, :update, :destroy] + respond_to :html, :xml, :json + def new + @tag_alias = TagAlias.new + respond_with(@tag_alias) end def edit + @tag_alias = TagAlias.find(params[:id]) + respond_with(@tag_alias) end def index + @search = TagAlias.search(params[:search]) + @tag_aliases = @search.paginate(:page => params[:page]) + respond_with(@tag_aliases) end def create + @tag_alias = TagAlias.create(params[:tag_alias]) + respond_with(@tag_alias) end def update + @tag_alias = TagAlias.find(params[:id]) + @tag_alias.update_attributes(params[:tag_alias]) + respond_with(@tag_alias) end def destroy + @tag_alias = TagAlias.find(params[:id]) + @tag_alias.destroy + respond_with(@tag_alias) end - def destroy_cache + def cache + @tag_alias = TagAlias.find(params[:id]) + @tag_alias.clear_cache + render :nothing => true end end diff --git a/app/views/tag_aliases/edit.html.erb b/app/views/tag_aliases/edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tag_aliases/new.html.erb b/app/views/tag_aliases/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/test/factories/tag_alias.rb b/test/factories/tag_alias.rb index f96bee565..aebf276b8 100644 --- a/test/factories/tag_alias.rb +++ b/test/factories/tag_alias.rb @@ -1,2 +1,4 @@ Factory.define(:tag_alias) do |f| + f.antecedent_name "aaa" + f.consequent_name "bbb" end diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index 50bc5f7f2..ef46c6254 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -1,8 +1,87 @@ require 'test_helper' class TagAliasesControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + context "The tag aliases controller" do + setup do + @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