新增ariticle_controller_test文件

This commit is contained in:
HuangQi 2016-01-05 20:28:33 +08:00
parent 08b7b72909
commit 4d902ef9fe
2 changed files with 77 additions and 0 deletions

View File

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

View File

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