From b1996e56940caa409c8d8f3bc9170d2545434b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Sat, 23 Jun 2018 22:55:40 +0200 Subject: [PATCH] Check page between AJAX requests in proposals spec. There was a flaky spec supporting proposals. It's hard to reproduce and be sure about what was going on, so here is my best guess. Given the code: ``` within(".proposals-list") { click_link proposal.title } within("#proposal_#{proposal.id}_votes") { click_link('Support') } ``` The first clicked link generates an AJAX request. Usually, Capybara would wait for the AJAX request to generate a "Support" link in the element `#proposal_XX_votes`. However, there's already a `#proposal_XX_votes` element with a "Support" link on the proposals index page! So Capybara doesn't have to wait for the AJAX request to finish before clicking the "Support" link. From then on, anything can happen. Another option that works: ``` within(".proposals-list") { click_link proposal.title } within(".proposal-show #proposal_#{proposal.id}_votes") { click_link('Support') } ``` With this code, the link selector fails on the proposals index page, and Capybara waits for the AJAX request to finish. Related to issue #2558. --- spec/features/management/proposals_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/management/proposals_spec.rb b/spec/features/management/proposals_spec.rb index 8dda865d7..ca33e3399 100644 --- a/spec/features/management/proposals_spec.rb +++ b/spec/features/management/proposals_spec.rb @@ -159,6 +159,7 @@ feature 'Proposals' do click_link "Support proposals" within(".proposals-list") { click_link proposal.title } + expect(page).to have_content proposal.code within("#proposal_#{proposal.id}_votes") { click_link('Support') } expect(page).to have_content "1 support"