From 4d902ef9fe4d3f0aa29c7827b31aea1b86507485 Mon Sep 17 00:00:00 2001 From: HuangQi <1321694949@qq.com> Date: Tue, 5 Jan 2016 20:28:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eariticle=5Fcontroller=5Ftest?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/controllers/articles_controller_test.rb | 46 +++++++++++++++++++ test/controllers/articles_controller_test.rb~ | 31 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/controllers/articles_controller_test.rb create mode 100644 test/controllers/articles_controller_test.rb~ diff --git a/test/controllers/articles_controller_test.rb b/test/controllers/articles_controller_test.rb new file mode 100644 index 0000000..bb72ffa --- /dev/null +++ b/test/controllers/articles_controller_test.rb @@ -0,0 +1,46 @@ +require 'test_helper' +require 'articles_controller' + +class ArticlesControllerTest < ActionController::TestCase + setup do + @controller = AriticlesController.new + @ariticle = Ariticle.new + @ariticle.title = 'title1' + @ariticle.tags = 'tags1' + @ariticle.source = 'source1' + @ariticle.content = 'content1' + @ariticle.save + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:articles) + end + + test "should show article" do + get :show, id: @ariticle.id + assert_response :success + end + + test "should create ariticle" do + post :create,:ariticle =>{:title=>'title1', :tags=>'tags1', :source=>'source', :content=>'content1'} + assert_not_nil session[:ariticle_id] + assert_redirected_to article_path(@ariticle) + end + + test "should destroy article" do + assert_difference('Article.count', -1) do + delete :destroy, id: @article.id + end + + assert_redirected_to articles_path + end + + test "destroy_wrong" do + post :destroy, :ariticle=>{:username=>'title1'} + assert_response :success + assert_equal '删除失败', flash[:error] + end + +end diff --git a/test/controllers/articles_controller_test.rb~ b/test/controllers/articles_controller_test.rb~ new file mode 100644 index 0000000..889cea5 --- /dev/null +++ b/test/controllers/articles_controller_test.rb~ @@ -0,0 +1,31 @@ +require 'test_helper' +require 'articles_controller' + +class ArtilesControllerTest < ActionController::TestCase + setup do + @controller = AritilesController.new + @aritile = Aritile.new + @aritile.title = 'title1' + @aritile.tags = 'tags1' + @aritile.source = 'source1' + @aritile.content = 'content1' + @aritile.save + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:articles) + end + + test "should show article" do + get :show, id: @aritile.id + assert_response :success + end + + test "should create aritile" do + post :create,:aritile =>{:title=>'title1', :tags=>'tags1', :source=>'source', :content=>'content1'} + assert_not_nil session[:aritile_id] + assert_redirected_to article_path(@article) + end +end