Commit Graph

47 Commits

Author SHA1 Message Date
Javi Martín
c614b0bc97 Run test coverage just on the master branch
Since we changed the way we integrate coveralls in commit 8ed8cc8b9,
we're getting 6 additional checks displayed in our pull requests.

We don't need these checks, and they only add noise. The only reason we
use coveralls is to know the test coverage in our master branch.

So we're changing the code so coveralls only runs on the master branch.

There's also a chance that the test suite will be faster because it
doesn't need to keep track of the coverage, although I haven't noticed any
significant differences during my tests.

I haven't found a more elegant way to say that a certain step should
only be run on push on master, so I'm setting the environment variable
we were already using.
2023-03-04 01:29:03 +01:00
Javi Martín
8ed8cc8b93 Use Coveralls Github Action to send test reports
Coveralls stopped working back in July when we reached build number 3790
because back when we used Travis we created builds from numbers 3791 to
35700.

After trying to change the numbers in several ways, all of them
resulting in a "No build matching CI build number" message, we're trying
the Github Action provided by Coveralls instead. In order to make it
work, we need to add the `simplecov-lcov` gem and generate the report at
`coverage/lcov.info`. Note that, for some reason, `simplecov-lcov`
doesn't seem to depend on `simplecov` and we need `simplecov` 0.18 or
later, so we're manually adding this dependency as well.
2022-11-29 14:51:22 +01:00
Eduardo Vilar
382abb3666 Add multitenancy with apartment
Co-Authored-By: Javi Martín <javim@elretirao.net>
2022-11-09 17:52:05 +01:00
Javi Martín
fed82b0024 Add a way to mark tests as consul/consul exclusive
Until now, when institutions made custom changes which made certain
tests obsolete, they didn't have a clear way to deal with the failing
tests. They would either:

1. Stop running the test suite
2. Run the test suite and get test failures 100% of the time
3. Comment the failing tests
4. Modify the failing tests in order to keep them in sync with the code

Solution 1 would be suicide from a maintenance perspective, although it
could work if only a couple of small custom changes were done.

Solution 2 would make it really hard to differenciate between "false
failures" and "real failures" when running the test suite.

Solution 3 would cause many conflicts when updating to a newer version
of Consul.

Solution 4 could make sense sometimes (big tests where only one line
needs to be changed), but it would also cause conflicts when updating
Consul.

So now, we're giving an alternative to solution 3 by making it easier to
exclude a test.

For tests that still need to be changed, when to use this solution
combined with a custom test and when to use solution 4 will have to be
decided on a per-case basis.
2022-01-03 13:33:37 +01:00
Javi Martín
174f765074 Make component tests fail when using within
This way we avoid writing useless tests which always pass.
2021-10-18 13:51:32 +02:00
Javi Martín
e97c375063 Add method to stub current_user in component tests
We're choosing `sign_in` instead of `login_as` because IMHO component
tests are more similar to controller tests than they are to system
tests.
2021-09-08 12:39:36 +02:00
dependabot[bot]
ff20b8a02e Bump factory_bot_rails from 4.8.2 to 6.2.0
Note we're changing the parent strategy because its default value
changed in Factory Bot 5. We're keeping the old one so it's compatible
with our test suite.

We're also removing the rubocop rule for static attributes because in
factory bot 5 this syntax is invalid and will raise an error, so there's
no need for rubocop to remind us about it.

Bumps [factory_bot_rails](https://github.com/thoughtbot/factory_bot_rails) from 4.8.2 to 6.2.0.
- [Release notes](https://github.com/thoughtbot/factory_bot_rails/releases)
- [Changelog](https://github.com/thoughtbot/factory_bot_rails/blob/master/NEWS.md)
- [Commits](https://github.com/thoughtbot/factory_bot_rails/compare/v4.8.2...v6.2.0)

---
updated-dependencies:
- dependency-name: factory_bot_rails
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 16:32:36 +02:00
Senén Rodero Rodríguez
7a33314ceb Remove Capybara default_set_options for system tests using the Rack Test driver
The next warning is flooding the tests log:

`Options passed to Node#set but the RackTest driver
doesn't support any - ignoring`

As the rack test driver does not support any option, we
get rid of all `default_set_options` before each system
spec that uses this driver.
2021-06-10 12:33:55 +02:00
Javi Martín
de9c261c0e Clear fields in tests before filling them in
There seems to be an issue with capybara or chromedriver which results
in `fill_in` sometimes appending to an input rather than overwriting
[1], causing some tests to fail under certain circumstances.

Clearing fields before filling them in solves the issue.

Note we're now getting warnings on all tests using the rack driver. I
haven't found a way to avoid the `clear: :backspace` option in
non-JavaScript tests, so to avoid the annoying warnings we should reduce
the number of tests using the rack driver even more.

[1] See issue 2419 in https://github.com/teamcapybara/capybara/issues
2021-04-09 17:54:21 +02:00
Javi Martín
8ed09adcaf Extract method to generate app host in tests
On JavaScript tests, Rails URL methods don't include the port when
invoked from a test, but they do when invoked from the browser. This was
causing some tests to fail with Selenium.
2021-04-07 14:32:49 +02:00
Julian Herrero
ba432c9f7f Increase browser window size in tests
Nobody uses a small screen like that, so we now test with a more close
to real life environment
2021-04-07 14:32:49 +02:00
Javi Martín
45693e084b Integrate coveralls with github actions
Somehow I thought it worked automatically, but we had to provide the
token.

The configuration is based on Coveralls instructions to run parallel
builds [1].

Alternatively we could use the Coveralls GitHub Action [2] which
slightly simplifies the workflow configuration and removes the
dependency of the coveralls gem. However, it also adds a dependency on
simplecov-lcov and requires configuring it to renerate LCOV files on
each run, so the benefits of using it are not that big.

[1] https://docs.coveralls.io/parallel-build-webhook
[2] https://github.com/coverallsapp/github-action/
2021-04-02 20:33:23 +02:00
Javi Martín
b214205d8f Use Capybara to disable animations in tests
We were doing it manually, but Capybara offers an option which does the
exact same thing.

This way we also apply the NoJavascriptTagHelper ERB rule, which
reported one error in the `disable_animations_in_tests` partial.
2021-02-05 17:46:23 +01:00
taitus
602b22edfd Allow tags to be removed with the keyboard
We improved accessibility by overwriting the setIcon method in the library.
Now we render a button and add the aria-label attribute.
2021-01-20 19:18:57 +01:00
Javi Martín
375134ea04 Run the test suite using GitHub Actions
Using GitHub Actions has a few advantages over using Travis CI:

* More jobs can be run in parallel
* All CONSUL repositories on GitHub will be configured automatically

Besides, Travis have recently changed their policy twice. First, they
announced their site for free software projects would be shut down but
free software projects could still use their site for private projects.
And then, they limited the usage of their services for free software
projects.

Just like we used to do with Travis, we're enabling builds for pull
requests but not for pushed branches.

We're also building the master branch. Even if we never push to the
master branch directly, we're aware other CONSUL repositories do, so
we're running the tests for this case.
2020-11-23 14:00:33 +01:00
Javi Martín
baefc249f0 Allow using components with view_component
While Rails provides a lot of functionality by default, there's one
missing piece which is present in frameworks like Django or Phoenix: the
so-called "view models", or "components".

It isn't easy to extract methods in a standard Rails view/partial, since
extracting them to a helper will make them available to all views, and
so two helper methods can't have the same name. It's also hard to
organize the code in modules, and due to that it's hard to figure out
where a certain helper method is supposed to be called from.
Furthermore, object-oriented techniques like inheritance can't be
applied, and so in CONSUL customizing views is harder that customizing
models.

Components fix all these issues, and work the way Ruby objects usually
do.

Components are also a pattern whose popularity has increased a lot in
the last few years, with JavaScript frameworks like React using them
heavily. While React's components aren't exactly the same as the
components we're going to use, the concept is really similar.

I've always liked the idea of components. However, there wasn't a stable
gem we could safely use. The most popular gem (cells) hasn't been
maintained for years, and we have to be very careful choosing which gems
CONSUL should depend on.

The view_component gem is maintained by GitHub, which is as a guarantee
of future maintenance as it can be (not counting the Rails core team),
and its usage started growing after RailsConf 2019. While that's
certainly not a huge amount of time, it's not that we're using an
experimental gem either.

There's currently a conflict between view_component and wicked_pdf.
We're adding a monkey-patch with the fix until it's merged in
wicked_pdf.
2020-10-19 18:56:02 +02:00
Javi Martín
3267c81ba0 Upgrade to Rails 5.2
All the code in the `bin/` and the `config/` folder has been generated
running `rake app:update`, except the `escape_javascript_fix` file,
which we've removed since the code there is already included in Rails
5.2.
2020-10-15 14:46:20 +02:00
Javi Martín
72c2b87227 Wait till CKEditor is ready before checking it
With chromedriver >= 80, the tests are freezing sometimes, particularly
when the same editor is loaded again.

We don't know whether it's a CKEditor issue or a chromedriver issue. In
the past we've had some errors related to CKEditor trying to load the
same instance twice and we aren't sure they have been fixed since we
could never reproduce them.

It could be a coincidence, though. If we modify the views so the only
content of the `<body>` tag is a textarea with the `html-area` class,
chromedriver freezes even if we only access the page once. So maybe
we're only detecting the problem on the second visit because the second
request is faster than the first one.

Since chromedriver no longer hangs after this change, we don't have to
force any chromedriver version anymore.
2020-06-09 13:29:56 +02:00
Javi Martín
2c4acb0bf7 Use chromedriver 2.38
The latest stable version is causing problems on some machines, hanging
forever in tests involving frames. So we're installing an old version
which works with the latest Chrome.

Note this means we're using an unsupported version. Officially, only the
latest chromedriver supports the latest Chrome.

We're using 2.38 instead of a more recent one (like 2.40) because it's
the one we specified in our Dockerfile.

See also:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=3361
2020-05-25 15:50:36 +02:00
Javi Martín
7e702fc7ed Fix DB corruption in system tests after exceptions
This is a known bug in Rails, fixed in the Rails 5.2 and Rails 6.x
branches:

https://github.com/rails/rails/pull/32293/commits/5c4e1338
2020-04-24 15:43:54 +02: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
Julian Herrero
cb3a1f2860 Update chromeOptions for newer versions of chromedriver 2019-11-14 11:58:39 +07:00
Javier Martín
cb6539d170 Merge pull request #3537 from PierreMesure/set-locales-in-test-environment
Set locales in test environment to avoid failed specs
2019-09-11 18:43:03 +02:00
Pierre Mesure
7fc4106780 Cleaning a few lines 2019-09-08 22:39:01 +02:00
Javi Martín
8bb5462253 Use capybara-webmock to avoid external requests
The images from OpenStreetMap take a while to load, sometimes even
causing Net::ReadTimeout errors if the internet connection is slow. It's
happened a lot recently on Travis builds.

Using capybara-webmock we guarantee the test suite doesn't fail due to
network issues.
2019-09-07 13:09:05 +02:00
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
Javi Martín
ea9576096b Don't load tasks if they're already loaded
We were having problems under certain conditions with Travis and
Knapsack where tasks were still being loaded twice and so they were
being executed twice.
2018-11-30 17:28:59 +01:00
Javi Martín
1a5b73a0bd Don't load tasks several times in specs
Calling `load_tasks` in several files made rails load the tasks several
times, and so they were executed several times when called.

Since the milestone migration can't be executed twice in a row (it would
fail with duplicated ID records), loading the tasks several times made
the milestone migrations task specs fail.
2018-11-30 14:15:21 +01:00
Angel Perez
ff1fced609 Update Dockerfile to install Headless Chrome 2018-06-07 14:11:16 -04:00
Angel Perez
eb2926ab42 Fix failing scenario related to Headless Chrome window-size flag 2018-03-27 14:47:50 -04:00
Angel Perez
0bf4afe8bc Replace PhantomJS/Poltergeist config with Headless Chrome 2018-03-27 14:47:48 -04:00
rgarcia
7b7a426f6a Run Coveralls only in Travis CI
We were seeing a log message when running specs locally

```
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.
```

As Coveralls is mainly used in Travis CI, we do not need to load it in
every spec run
2018-02-06 12:22:34 +01:00
Bertocq
1441de5107 Enable RSpec/HookArgument cop and fix issues
To be consistent about before/after arguments, as `:each` or `:example`
 are same and default scopes, best not to send an argument in those
 scenarios.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
2018-01-07 02:07:19 +01:00
Amaia Castro
551e8dc6c1 Increase Poltergeist timeout in specs
This is to try to avoid flaky js specs in Travis
2017-01-19 13:38:06 +01:00
Juanjo Bazán
4a888e95c2 disables js fx in specs via poltergeist config 2016-03-04 12:26:47 +01:00
Alberto Garcia Cabeza
3752f3a53b Adds foundation 6 🎉 2016-02-26 19:33:33 +01:00
kikito
eda47effc4 Configures tests to minimize flackyness
Reference: https://bibwild.wordpress.com/2016/02/18/struggling-towards-reliable-capybara-javascript-testing/

The only thing I did not do was removing the random order in the tests.
2016-02-24 11:37:07 +01:00
kikito
e3cbae4f02 Makes capybara exact. Should fix some randomly-failing specs 2015-09-02 18:05:43 +02:00
David Gil
de15bbe911 adds feature tests for sign up and sign using OAuth 2015-08-25 14:15:04 +02:00
rgarcia
c2091f570c integrates coveralls in test suite 2015-08-05 14:16:58 +02:00
Juanjo Bazán
9073037a45 makes test suite default to :en locale
ref: #38
2015-07-28 12:52:10 +02:00
kikito
be173ff581 removes use_transaction_fixtures from rails_helper
It is already configured in spec_helper.rb (and makes other things fail)
2015-07-27 19:07:02 +02:00
kikito
1e2f8704a5 Change order in requires to fix tests 2015-07-27 19:01:06 +02:00
rgarcia
0aaa8169f0 tmp commit [#21] 2015-07-27 11:12:55 +02:00
rgarcia
8f78509b0c adds basic devise feature specs 2015-07-17 19:53:19 +02:00
rgarcia
223eb06da2 configures capybara [#4] 2015-07-16 17:07:12 +02:00
rgarcia
4aa16e78c2 configure rspec 2015-07-15 13:59:26 +02:00