Commit Graph

6 Commits

Author SHA1 Message Date
Javi Martín
006128da57 Query the database before a visit in campaigns test
This test was failing sometimes. One possible cause (although it might
not be the only one) is we were querying the database with
`Campaing.last` after starting the process running the browser with a
`visit`. In the past doing so has resulted in database inconsistencies
while running the tests.

Since after running the test more than 1500 times we weren't able to
reproduce the failure, it's possible that this change doesn't fix the
issue which caused the test to fail, but in the worst case scenario we
reduce the number of possible reasons why it fails.
2021-11-18 15:04:22 +01:00
Senén Rodero Rodríguez
652f85cba3 Update spec expectations to avoid flake specs
The last expectation we were using in this test is satisfied before
going back to the admin stats page, as the campaing2 name is not
present before clicking the `Go back` link. Because of this, the
test could end while the request thrown by the `Go back` link is
not completed yet, which can collide with the following test and
cause a flake spec.
2021-11-16 16:12:05 +01:00
Javi Martín
28e720a1ec Make sure we use non-existent IDs in campaign test
Previously, depending on the database status, it could be possible that
the ID of the campaign2 record was exactly 999 and this test could fail.
2021-06-30 16:00:07 +02:00
Javi Martín
855f47f386 Create campaings before running campaigns tests
We were defining campaigns with `let`. That meant they weren't created
until these methods were used in the tests.

For the test "Do not track erroneous track_ids", that meant the line
`expect(page).not_to have_content campaign2.name.to_s` wasn't really
testing anything, since before this line is executed, the campaign2
wasn't in the database at all, and so obviously its name wouldn't be on
the stats page.

For the test "Track email templates", it meant we were creating the
campaign2 record after visiting the campaign1 page with the browser.
Creating records in the tests after starting the browser might be the
reason why this test has recenty failed in our CI [1]:

 1) Email campaigns Track email templates
     Failure/Error: ds.add params[:event].titleize, Ahoy::Event.where(
                    name: params[:event]).group_by_day(:time).count
     ActiveRecord::StatementInvalid:
       PG::ProtocolViolation: ERROR:  bind message supplies 0
       parameters, but prepared statement "" requires 1
     # ./app/controllers/admin/api/stats_controller.rb:13:in `show'

Using `let!` to create the campaings before the browser starts improves
the situation.

[1] https://github.com/consul/consul/runs/2952333023
2021-06-30 16:00:00 +02:00
Javi Martín
3da4ee00b8 Simplify tests requiring admin login
We were repeating the same code over and over (with a few variants) to
setup tests which require an administrator. We can use a tag and
simplify the code.
2020-12-02 15:33:19 +01:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00