2012-04-22 10 views
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の#

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でfill_information_for kInformation私はこのようなカスタムバリデーションメソッドを持っています

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 ..あなたは、これらのテストのために

答えて

1

何データベース戦略を使用していますか?トランザクション内で実行されている場合、データは実際にはデータベースに永続化されることはありません。実行中のスレッドまたはプロセスの数に関係なく、データが永続化されることが保証されているため、これらの手順には他の方法を使用する必要があります。 Ajaxリクエストを作成すると、そのリクエストはサーバーとは別にリクエストされ、データベーストランザクションはそのリクエストに対してのみ使用できます。私はキュウリ:: Railsの:: Database.javascript_strategy =渡さ

Cucumber::Rails::Database.javascript_strategy = :shared_connection 
+0

:私のアプリケーションで

、私は共有接続使用してJavaScriptのテストのための設定を持っているenv.rbでshared_connectionを、しかし、今私get Mysql2 :: Error:この接続はまだ結果を待っています。結果が得られたら、もう一度試してください: – dilshod

+1

ajaxリクエストが非同期であり、キュウリがreqeustを終了する前に次のステップに移るからです。次のステップに移動する前にイベントが終了するのを待つか、ページ上の要素を見つけて強制的に待機させるなど、いくつかのオプションがあります。 –

+0

ここにhttp://pivotallabs.com/users/mgehard/blog/articles/1671-waiting-for-jquery-ajax-calls-to-finish-in-cucumberの例があります。詳細はhttpsのAJAXセクションをご覧ください://github.com/jnicklas/capybara –

関連する問題