问卷预构件添加

This commit is contained in:
zhuhao 2015-01-31 10:03:24 +08:00
parent 768e06ea8a
commit a239cce03d
3 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,127 @@
require 'spec_helper'
describe PollController do
describe 'poll' do
it 'is a valid poll' do
#expect( FactoryGirl.build(:poll)).to be_valid
expect(create(:poll)).to be_valid
end
end
# describe 'GET #index' do
# 2 context 'with params[:letter]' do
# 3 it " populates an array of contacts starting with the letter" do
# 4 smith = create( :contact, lastname: 'Smith' )
# 5 jones = create( :contact, lastname: 'Jones' )
# 6 get :index, letter: 'S'
# 7 expect(assigns( :contacts)) . to match_array( [ smith] )
# 8 end
# 9
# 10 it " renders the :index view" do
# 11 get :index, letter: 'S'
# 12 expect(response) . to render_template :index
# 13 end
# 14 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
@poll=Poll.new
#expect(assigns(:course)).to be_true
#expect(assigns(:polls)).to match_array(['','',''])
# expect(assigns(:polls)).to eq ('abc')
end
end
# describe 'GET #show' do
# 2 it " assigns the requested contact to @contact" do
# 3 contact = create( :contact)
# 4 get :show, id: contact
# 5 expect(assigns( :contact)) . to eq contact
# 6 end
# 78
# it " renders the :show template" do
# 9 contact = create( :contact)
# 10 get :show, id: contact
# 11 expect(response) . to render_template :show
# 12 end
# 13 end
describe 'GET #show' do
it "it show the poll by poll_id"do
@poll=create( :poll)
get :show ,id: @poll
expect(assigns( :poll_questions)).to eq @poll
end
end
describe 'GET #new' do
it "save the poll success "do
PollController.any_instance.stubs(:valid?).returns(true)
get 'new'
#@poll=Poll.new
response.should redirect_to(edit_poll_path @poll.id)
#expect(assigns( :poll)).to be_a_new( Poll)
end
it"should redirect new template on fiald save"do
PollController.any_instance.stubs(:valid?).returns(true)
get 'new'
response.should redirect_to(news_path)
end
end
describe 'GET #edit' do
end
describe 'POST #create' do
end
describe 'PATCH #updte' do
end
# describe 'DELETE #destroy' do
# before :each do
# @contact = create( :contact)
# end
#
# it " deletes the contact" do
# expect{
# delete :destroy, id: @contact
# } . to change( Contact, :count) . by( - 1 )
# end
#
# it " redirects to contacts#index" do
# delete :destroy, id: @contact
# expect(response) . to redirect_to contacts_url
# end
# end
# 删除问卷的测试
describe 'DELETE #destroy' do
it "deletes the poll"do
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
end
end
describe 'POST #create' do
end
describe 'PATCH #update' do
end
end

View File

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :poll_questions do
association :poll
question_title "php"
poll_id ""
end
end

10
spec/factories/polls.rb Normal file
View File

@ -0,0 +1,10 @@
#require 'faker'
FactoryGirl.define do
factory :poll do
polls_name "php"
polls_type "Course"
polls_group_id "150"
polls_status "2"
end
end