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.
This commit is contained in:
Javier Martín
2018-06-23 22:55:40 +02:00
parent 24e4f027b1
commit b1996e5694

View File

@@ -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"