0
我有这样为什么发生这种情况与黄瓜测试?
Given /^initial data$/ do |table|
@schedule_05 = Factory.build :schedule_05
@schedule_05.save
puts "count of rows #{@schedule_05.cycles.count}" - # is 7
end
#....... there are same steps and where filling text fields and so on/
When /^i click a submit button "([^"]*)" in form$/ do |runs|
click_button(runs) # this is ajax request
end
Then /^count of SchOfWorkInformation is 365$/ do
puts "count of rows #{ScheduleOfWorking.count}" # is - 1
s_c = ScheduleOfWorking.find_by_schedule_code("05") # is too 1
puts "05 schedule is presents #{s_c.blank?}" # false
unless s_c.blank?
puts "05 schedule is presents #{s_c.date_of_countings.blank?}" #false
end
end
步骤,当我点击提交方案涉及控制器ScheduleOfWorkingController的填充作用
def filling
unless request.xhr?
@classifier_schedule = ScheduleOfWorking.classifiers_numbers
@schedule_number = ScheduleOfWorking.classifiers_numbers false
else
if params[:date_begin].blank? || params[:date_end].blank?
render :js => "alert('date fields is empty !')"
return
end
ScheduleOfWorking.fill_information_for(params[:date_begin].to_date,params[:date_end].to_date)
end
末
ScheduleOfWorking#fill_information_for
def self.fill_information_for(date_begin, date_end)
sch = all
sch.each do |e_sch|
e_sch.date_of_countings.each do |d_counting|
h_calculate = d_counting.roll_cycle(date_begin, date_end)
transaction do
SchOfWorkInformation.delete_all("(date >= '#{date_begin}' and date <= '#{date_end}') and schedule_code = #{d_counting.sch_code}")
SchOfWorkInformation.create! h_calculate
end
end
end
end
在SchOfWor k信息我有这样的自定义验证方法
def customer_validate
s = SchOfWorkInformation.where(:date => self.date, :schedule_code => self.schedule_code).first
if !s.blank? && (new_record? || s.id != self.id)
self.errors[:base] = "Запись не уникально!(date=#{self.date.to_s(:db)}, schedule_code=#{self.schedule_code})"
end
sch_number = schedule_code[0..1].blank? ? "0" : schedule_code[0..1]
session_number = schedule_code[2].blank? ? "0" : schedule_code[2]
logger.info "---------------------------------------"
ss_a = ScheduleOfWorking.all
s = ScheduleOfWorking.where("schedule_code='#{sch_number}'").
joins(:date_of_countings).
where("date_countings.session_number=#{session_number}")
# In Given section of my step i load the data, but s.balnk? gives true
if s.blank?
self.errors[:base] = "Schedule - #{sch_number} with session number #{session_number}), is not exists in DB"
end
end
为什么我的数据在验证方法中丢失?请帮助!
在开发环境。所有的权利,但在测试不。
..sorry长信..
您使用的这些测试
我经过黄瓜::滑轨:: Database.javascript_strategy =:shared_connection在env.rb,但现在我得到Mysql2 ::错误:此连接仍在等待结果,请在结果后再试一次:在我的服务器日志中。 – dilshod 2012-04-22 18:27:22
这是因为ajax请求是异步的,并且在完成reqeust之前黄瓜移动到下一步。您有几个选项,包括在转到下一步之前等待事件完成或在页面上定位某个元素并强制它等待。 – 2012-04-22 19:12:44
下面是一个示例http://pivotallabs.com/users/mgehard/blog/articles/1671-waiting-for-jquery-ajax-calls-to-finish-in-cucumber或查看AJAX部分了解更多信息https ://github.com/jnicklas/capybara – 2012-04-22 19:13:27