Commit Graph

18381 Commits

Author SHA1 Message Date
Javi Martín
f87d4b589d Add and apply Naming/BlockForwarding rubocop rule
This syntax has been added in Ruby 3.1.

Not using a variable name might not be very descriptive, but it's just
as descriptive as using "block" as a variable name. Using just `&` we
get the same amount of information than using `&block`: that we're
passing a block.

We're still using `&action` in `around_action` methods because here we
aren't using a generic name for the variable, so (at least for now) we
aren't running this cop on controllers using `around_action`.
2023-09-12 15:17:28 +02:00
Javi Martín
fd9169e0d6 Update Style/HashSyntax Rubocop rule
Ruby 3.1 adds the option for hash shortcuts, so it's possible to write
`{ user: , poll: }` instead of `{ user: user, poll: poll }`.

By default, Rubocop expects the new syntax in Ruby 3.1. While right now
I absolutely hate this new syntax, we're allowing both the old and the
new styles because we might start adopting it once we get used to it.
2023-09-12 15:17:17 +02:00
Javi Martín
e74eff217b Upgrade Ruby to version 3.1.4
Note we updated the `mail` gem in commit 103742847, which is necesary
for Ruby 3.1 because it adds the net-smtp dependency. The net-smtp
library was removed from Ruby in Ruby 3.1, and if we don't include it,
we get an error:

```
cannot load such file -- net/smtp (LoadError)
```

We're also updating the Bundler version in the Gemfile.lock so it's the
one included in Ruby 3.1. Without updating it, we get a warning:

```
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)'
has been deprecated. Please call `DidYouMean.correct_error(error_nam e,
spell_checker)' instead.
```

Finally, in order to make Capistrano work, we need to add a couple more
changes:

* Make the net-ssh gem compatible with SSL 3.0; done in commit b2eec088b
* Explicitly allow aliases in the `deploy-secrets.yml` file because
  Psych 4.x (included in Ruby 3.1) doesn't load aliases without this
  option
2023-09-12 15:17:17 +02:00
Javi Martín
bf96136ccf Merge pull request #5151 from consuldemocracy/rails_6.1
Upgrade to Rails 6.1
2023-09-12 14:48:08 +02:00
Javi Martín
3527398db1 Remove no longer needed call to default_scoped
Automatically using `default_scoped` in this context is the default
behavior in Rails 6.1.
2023-09-11 23:40:37 +02:00
Javi Martín
08b12a78ff Directly delete the "organization is invalid" error
We were getting a warning since upgrading to Rails 6.1:

DEPRECATION WARNING: Calling `delete` to an ActiveModel::Errors messages
hash is deprecated. Please call `ActiveModel::Errors#delete` instead.

So we're deleting the error instead of deleting the message.
2023-09-11 23:40:37 +02:00
Javi Martín
f03ea9d817 Don't include extensions when rendering templates
We were getting a deprecation warning:

DEPRECATION WARNING: Rendering actions with '.' in the name is
deprecated: welcome/_recommended_carousel.html.erb
2023-09-11 23:40:37 +02:00
Javi Martín
b2c8fee059 Ignore dots in slugs when rendering custom pages
We were getting a warning in one of the tests:

DEPRECATION WARNING: Rendering actions with '.' in the name is
deprecated: application/nonExistentJavaScript.js

I haven't found a case where the behavior on production environments is
different due to this change; the application seems to behave the same
way as it used to. So I'm not adding tests for this change.
2023-09-11 23:40:37 +02:00
Javi Martín
633ccf80f6 Use Rails 6.1 defaults and overwrite them
We can remove the `new_framework_defaults_6_1` file by using Rails 6.1
default options and overwriting the one we haven't enabled.

We've experienced problems while running the tests (probably the same
would happen on production) when enabling the `has_many_inversing`
option. For example, after creating a legislation answer for a question
with no answers, calling `question.answers_count` would then return `2`
instead of `1`.

So we aren't enabling this option.
2023-09-11 23:40:37 +02:00
Javi Martín
b4da795f79 Preload CSS and JavaScript files
This is the default setting in Rails 6.1, and generates an extra tag in
the HTML which tells the browser to download and cache these files as
soon as possible, even before they're needed.

This might not be that relevant in our application, since on most pages
we only generate one CSS and one JS file. But it might make it easier to
move the `javascript_include_tag` statement to the bottom of the page in
the future if we detect that doing so increases performance.
2023-09-11 23:40:37 +02:00
Javi Martín
4984ac44d3 Use the default job queue to deliver emails
This is the default in Rails 6.1 for Action Mailer, just like it's the
default for Active Storage.
2023-09-11 23:40:37 +02:00
Javi Martín
50dc9dee69 Disable legacy database connection handling
Since we aren't using the old way to handle multiple databases (because
we don't use multiple databases), we can safely enable this option
without breaking anything.
2023-09-11 23:40:37 +02:00
Javi Martín
fe94d84e81 Use 308 as SSL default redirect status
This way user agents will know that the redirection from HTTP to HTTPS
is permanent and not temporary, which is the case if we activate the
`force_ssl` option (which we do by default).
2023-09-11 23:40:37 +02:00
Javi Martín
05eecaf46c Return UTC offests in the utc_to_local method
We don't use this method anywhere, so we might use the new default in
Rails 6.1, which was added when Rails started using tzinfo 2.
2023-09-11 23:40:37 +02:00
Javi Martín
4fe9d4cbcf Use URL-safe CSRF tokens and SameSite in cookies
These measures increase protection against CSRF ataks. The only reason
Rails provides them as a configuration option is there are complex
applications that run one version of the code in some servers while
running an old version of the code in other servers might run into
issues because the the old version won't handle the tokens or cookies
generated by the new version.

Since most Consul applications use just one server and the ones with
more servers would only face this issue for a few seconds (while
upgrading to a new version of Consul Democracy), we can safely enable
these configuration options.
2023-09-11 23:40:37 +02:00
Javi Martín
e8c8b00e94 Skip after callbacks if terminated in active job
Not sure this configuration option does anything, though, since it's
been removed in Rails 7.0 because it was not halting the callbacks.

But, if it does nothing, it's the same as disabling it, which is what we
were doing until now, so in the end using the Rails 6.1 default value
does no harm.
2023-09-11 23:40:37 +02:00
Javi Martín
8a6b9dcb46 Delete action mailbox options since we don't use it
Simply uncommeting them raised an exception.
2023-09-11 23:40:37 +02:00
Javi Martín
8e2b7e231f Configure "retry jitter" option in active job
This way, when several jobs fail at the same time, not all of them will
be retried at the same time.
2023-09-11 23:40:37 +02:00
Javi Martín
600bc793a1 Store Active Storage variants in the database
This mostly benefit people using external services, as now there's no
need to query the service to check whether a variant exists.

For most Consul Democracy installations, this will probably not be
relevant, so we're sticking wih the default value.
2023-09-11 23:40:37 +02:00
Javi Martín
1f67318f84 Delete configuration options that are now redundant
These options are the default options in Rails 6.1, so we no longer need
to customize them.
2023-09-11 23:40:37 +02:00
Javi Martín
13eebe4d7a Remove Wicked PDF monkey patch
This patch was added in commit baefc249f because both ViewComponent and
Wicked PDF monkey-patched the `render` method and so they were
incompatible.

However, Rails 6.1 includes the patch used by ViewComponent, meaning
ViewComponent doesn't monkey-patch the `render` method anymore, and so
it's compatible with Wicked PDF.
2023-09-11 23:40:37 +02:00
Javi Martín
6e9df3be5a Upgrade to Rails 6.1
Note that `Capybara.app_host` now returns `nil` by default and that
breaks tests using `lvh.me` or our custom `app_host` method, so we're
setting `Capybara.app_host` to the value it had in earlier versions of
Rails. I also haven't found a way to remove the code to set the
integration session host in relationable tests which I mentioned in
commit ffc14e499.

Also note that we now filter more parameters, and that they match
regular expressions, so filtering `:passw` means we're filtering
`passwd`, `password`, ...
2023-09-11 23:40:37 +02:00
Javi Martín
6f1e845fbb Move time zone option to its right place
It is supposed to be set in the place where there's a comment related to
it, but we were setting it in another section of the configuration file.
2023-09-11 23:40:37 +02:00
Javi Martín
f329537adc Merge pull request #5233 from consuldemocracy/dependabot/bundler/sprockets-4.2.1
Bump sprockets from 4.2.0 to 4.2.1
2023-09-11 20:31:38 +02:00
dependabot[bot]
0dae07123a Bump sprockets from 4.2.0 to 4.2.1
Bumps [sprockets](https://github.com/rails/sprockets) from 4.2.0 to 4.2.1.
- [Release notes](https://github.com/rails/sprockets/releases)
- [Changelog](https://github.com/rails/sprockets/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rails/sprockets/compare/v4.2.0...v4.2.1)

---
updated-dependencies:
- dependency-name: sprockets
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 17:33:09 +00:00
Javi Martín
bf5be5cd92 Merge pull request #5234 from consuldemocracy/dependabot/bundler/web-console-4.2.1
Bump web-console from 4.2.0 to 4.2.1
2023-09-11 17:53:16 +02:00
Javi Martín
f05785a8f8 Merge pull request #5152 from consuldemocracy/remove_ie8_warning
Remove alert for Internet Explorer 8 and below
2023-09-11 16:36:35 +02:00
dependabot[bot]
90e726378a Bump web-console from 4.2.0 to 4.2.1
Bumps [web-console](https://github.com/rails/web-console) from 4.2.0 to 4.2.1.
- [Release notes](https://github.com/rails/web-console/releases)
- [Changelog](https://github.com/rails/web-console/blob/main/CHANGELOG.markdown)
- [Commits](https://github.com/rails/web-console/compare/v4.2.0...v4.2.1)

---
updated-dependencies:
- dependency-name: web-console
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 12:40:39 +00:00
Javi Martín
bc4be187d9 Merge pull request #5241 from consuldemocracy/dependabot/bundler/rubocop-rspec-2.23.2
Bump rubocop-rspec from 2.17.1 to 2.23.2
2023-09-11 14:39:36 +02:00
Javi Martín
ea913f9332 Use Capybara methods to find/click/check links
We applied the Capybara/SpecificMatcher in commit f52a86b46.  However,
this rule doesn't convert methods finding <a> tags to methods finding
links because <a> tags only count as links when they've got the `href`
attribute. For instance, in the `xss_spec.rb` file we check what happens
when clicking on an anchor tag because we're testing that the `href`
attribute has been removed and so we can't use `click_link`.

So, basically, we can't enable a rule to automatically detect when we're
using `have_css` instead of `have_link`, but we should still do it
because `have_link` adds an extra check which affects accessibility
since it makes sure the tag has the `href` attribute and so it's
recognizable as a link by screen readers.
2023-09-11 14:10:41 +02:00
Javi Martín
614b4fbe4c Add and apply FactoryBot/AssociationStyle rule
This rule was added in rubocop-factory_bot 2.23.0. We were following it
sometimes, and sometimes we were not.
2023-09-08 13:52:54 +02:00
Javi Martín
b88a01f641 Add and apply FactoryBot/RedundantFactoryOption rule
This rule was added in rubocop-factory_bot 2.23.0.
2023-09-08 13:39:26 +02:00
Javi Martín
3b2484af77 Add FactoryBot/FactoryAssociationWithStrategy rule
This rule was added in rubocop-factory_bot 2.23.0. Even if we always
follow it, it's a mistake that we've accidentally made in the past
during development.
2023-09-08 13:37:38 +02:00
Javi Martín
1d5f03be8c Add and apply RSpec/ReceiveMessages rubocop rule
This rule was added in rubocop-rspec 2.23.0. I didn't know this method
existed, and it makes the code more readable in some cases.
2023-09-08 13:31:42 +02:00
Javi Martín
9bb2bfdd06 Add and apply RSpec/Rails/NegationBeValid rule
This rule was added in rubocop-rspec 2.23.0. We were already applying it
most of the time.
2023-09-08 13:24:46 +02:00
Javi Martín
fc0511f4d3 Add and appy RSpec/Rails/TravelAround rubocop rule
This rule was added in rubocop-rspec 2.19.0.

When freezing time in a test, `travel_back` is called automatically when
the test finishes, so we can do it in a `before` block instead of an
`around` block.

Note this rule didn't detect our usage of `freeze_time` because we were
using it on cops with a certain tag, but I expect the rule to be able to
detect this usage in the future.
2023-09-08 13:16:24 +02:00
dependabot[bot]
aef78ee6f6 Bump rubocop-rspec from 2.17.1 to 2.23.2
Note that in rubocop-rspec 2.18.0, most Capybara cops were extracted to
a different gem, and the sam happened in rubocop-rspec 2.22.0 with
FactoryBot cops.

So we're adding both rubocop-capybara and rubocop-factory_bot as
dependencies.

Bumps [rubocop-rspec](https://github.com/rubocop/rubocop-rspec) from 2.17.1 to 2.23.2.
- [Release notes](https://github.com/rubocop/rubocop-rspec/releases)
- [Changelog](https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop-rspec/compare/v2.17.1...v2.23.2)

---
updated-dependencies:
- dependency-name: rubocop-rspec
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-08 12:46:41 +02:00
Javi Martín
49218118f2 Merge pull request #5240 from consuldemocracy/fix_erblint
Apply Style/InvertibleUnlessCondition rule to ERB files
2023-09-07 20:21:52 +02:00
Javi Martín
0b03c40b95 Apply Style/InvertibleUnlessCondition rule to ERB files
We forgot to do so in commit 28aafbd4b.
2023-09-07 19:49:45 +02:00
Javi Martín
21a268ab96 Remove alert for Internet Explorer 8 and below
Internet Explorer 8 was released in 2009 and people using it already
know that most web pages look broken on it, so we don't need to warn
them.

Removing it makes our application layout file much easier to read and
modify.
2023-09-07 19:44:54 +02:00
Javi Martín
caf7387f27 Merge pull request #5195 from consuldemocracy/dependabot/bundler/rubocop-1.56.2
Bump rubocop from 1.35.1 to 1.56.2
2023-09-07 19:42:21 +02:00
Javi Martín
28aafbd4bc Add and apply Style/InvertibleUnlessCondition rule
This rule was added in rubocop 1.44.0. It's useful to avoid accidental
`unless !condition` clauses.

Note we aren't replacing `unless zero?` with `if nonzero?` because we
never use `nonzero?`; using it sounds like `if !zero?`.

Replacing `unless any?` with `if none?` is only consistent if we also replace
`unless present?` with `if blank?`, so we're also adding this case. For
consistency, we're also replacing `unless blank?` with `if present?`.

We're also simplifying code dealing with `> 0` conditions in order to
make the code (hopefully) easier to understand.

Also for consistency, we're enabling the `Style/InverseMethods` rule,
which follows a similar idea.
2023-09-07 19:14:03 +02:00
Javi Martín
21ca96ae1c Fix conflictive debates with no votes
We originally added the `cached_votes_up > 0` in commit 4ce95e273
because back then `cached_votes_up` was used in the denominator. That's
no longer the case, and it doesn't make sense to mark a debate with 1
vote and 10 flags as conflictive but not doing it when the debate has no
votes and 1000 flags.

We're fixing the bug right now because we're about to change the
affected line in order to apply a new rubocop rule.
2023-09-07 19:08:36 +02:00
Javi Martín
e2542eed22 Merge pull request #5105 from consuldemocracy/rotate_logger
Rotate logs on production
2023-09-07 16:31:29 +02:00
Javi Martín
e077c7e890 Rotate log files on production and staging
The code based on the logger Rails uses by default; as mentioned in the
Rails configuration guide:

> [the logger] defaults to an instance of ActiveSupport::TaggedLogging
> that wraps an instance of ActiveSupport::Logger which outputs a log to
> the log/ directory. You can supply a custom logger, to get full
> compatibility you must follow these guidelines:
>
> * To support a formatter, you must manually assign a formatter from
>   the config.log_formatter value to the logger.
> * To support tagged logs, the log instance must be wrapped with
>   ActiveSupport::TaggedLogging.
> * To support silencing, the logger must include
>   ActiveSupport::LoggerSilence module. The ActiveSupport::Logger class
>   already includes these modules.
2023-09-07 15:58:16 +02:00
Javi Martín
11b962da8f Add and apply Style/MinMaxComparison rubocop rule
This rule was added in rubocop 1.42.0.
2023-09-07 13:09:11 +02:00
Javi Martín
daa35845da Add and apply Style/RedundantStringEscape rule
This rule was added in rubocop 1.37.0. It's particularly useful in the
background image spec, since now there's one less backslash to decipher
when reading the code :).
2023-09-07 13:09:11 +02:00
dependabot[bot]
ff04009e4a Bump rubocop from 1.35.1 to 1.56.2
Among many things, this version includes updates in the
`Layout/ExtraSpacing`, `Layout/SpaceAroundOperators` and
`Style/RedundantReturn` rules, which means we need to update the code in
some places in order to follow these rules.

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.35.1 to 1.56.2.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.35.1...v1.56.2)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-07 13:09:11 +02:00
Javi Martín
c3d666ddce Merge pull request #5188 from consuldemocracy/dependabot/bundler/rubocop-rspec-2.17.1
Bump rubocop-rspec from 2.4.0 to 2.17.1
2023-09-07 13:08:22 +02:00
Javi Martín
d729e6c05d Merge pull request #5221 from consuldemocracy/dependabot/bundler/rubocop-rails-2.20.2
Bump rubocop-rails from 2.15.2 to 2.20.2
2023-09-07 13:00:24 +02:00