使用Capybara创建新案例

时间:2013-10-28 18:50:47

标签: ruby-on-rails ruby capybara

我是ror的新手,我一直坚持在Capybara写测试。 我需要做的是测试新案例的创建 用户点击按钮。但是,当我检查眼镜是否看不到创建时。

require 'spec_helper'
 feature "User can create new case" to
 background do
 @ user = FactoryGirl.create (: sysadmin_user)     @ user.make_current
 @plan  = FactoryGirl.create(:plan)
 @ account = FactoryGirl.create (: account, plan: @plan, user: @user)

 @trial = FactoryGirl.create trial (:trial, account: @account) 
 @ trial.make_current
 @ trial_phase = FactoryGirl.create (: trial_phase, trial: @trial)

 login (@ user.email, @ user.password)
end


scenario 'create new case' to
 Case.where puts ("created_by =?", @ user.id).count #returns 0
 fill_in 'case_subject_identifier', with 'MyNewTest'
 expect {click_button ('Create New Case')}.to change(Case,:count).by(1)
 Case.where puts ("created_by =?", @ user.id).count #returns 0
end

这是控制器:

POST / case as HTML

def create`
@case = Case.where("subject_identifier = ? && trial_id = ?", params[:case]
[:subject_identifier], @current_trial.id).first
if @case || params[:case][:subject_identifier].blank?
respond_to :js
else`
params[:case][:subject_identifier]     
=sanitize_value(params[:case[:subject_identifier])    
if params[:case]
@case = Case.create(params[:case])``
if current_user.trial_member?(@current_trial, current_user)
@case.update_attributes(:location_id => current_user.default_location_id)
else
@case.update_attributes(:location_id => Location.find_by_name("None").id) 
end
@case.update_attributes(:trial_phase_id
=>TrialPhase.find_by_name("None").id,:access      
=> "None")
#redirect_to "/trial/#{@current_trial.id.to_s}/cases/#{@case.id.to_s}/case_view"
respond_to do |format|
format.js { render :js => %(window.location.pathname='#{'/trial
/'+@current_trial.id.to_s+'/cases/'+@case.id.to_s+'/case_view'}') }
end
end
end

0 个答案:

没有答案