polls_controller的index测试

This commit is contained in:
zhuhao 2015-02-02 10:58:14 +08:00
parent 94190acd2e
commit 98090d0461
2 changed files with 16 additions and 20 deletions

View File

@ -9,24 +9,17 @@ describe PollController do
end
end
describe "GET #index" do
# it "get the poll list" do
# @poll=create( :poll)
# @poll_php = create( :poll,polls_name: 'php' )
# @poll_java = create( :poll,polls_name: 'java' )
# @poll_ruby = create( :poll,polls_name:'ruby' )
# @poll_c = create( :poll,polls_name:'c',polls_group_id:'163' )
# get :index,polls_type:'Course',polls_group_id:'150'
#expect(assigns(:polls)).to eq @poll
#@poll=Poll.new
describe "GET#index" do
#expect(assigns(:course)).to be_true
#expect(assigns(:polls)).to match_array([@poll_php,@poll_java,@poll_ruby])
# expect(assigns(:polls)).to eq ('abc')
#end
it "assigns @polls" do
@poll =create(:poll)
get :index,polls_type:'Course',polls_group_id:'150'
expect(assigns(:poll)).to eq([@poll])
end
end
describe 'GET #show' do
it "it show the poll by poll_id"do
@poll=create( :poll)
@ -76,6 +69,7 @@ describe PollController do
end
context "with valid attributes" do
it"locates the requested @poll"do
#attributes_for 方法生成的不是 Ruby 对象,而是一个由属性组成的 Hash用来模拟浏览器和服务器之间的操作
patch :update ,id:@poll,poll:attributes_for( :poll)
expect(assigns(:poll)).to eq (@poll)
end
@ -93,7 +87,7 @@ describe PollController do
end
end
context "whit invalid attributes" do
# 更新失败
it"does not change the poll's attributes"do
@ -111,12 +105,14 @@ describe PollController do
before do
@poll=create(:poll)
end
# 测试是否删除了问卷
it "deletes the poll"do
expect { delete 'destroy',id: @poll }.to change( Poll, :count).by(-1)
expect{ delete 'destroy',id: @poll }.to change( Poll, :count).by(-1)
end
#测试删除问卷后是否转向了指定页面
it "redirects to poll#index"do
delete :destroy,id: @poll
expect(response).to redirect_to poll_url
expect(response).to redirect_to index_path
end
end

View File

@ -4,8 +4,8 @@ FactoryGirl.define do
factory :poll do
polls_name "php"
polls_type "Course"
polls_group_id "150"
polls_status "2"
polls_group_id 150
polls_status 2
polls_description "about php"
end
end