Commit Graph

19098 Commits

Author SHA1 Message Date
Javi Martín
995f7036de Run every linter separately in Github Actions
The main reason for this change is that Pronto doesn't run in pull
requests opened by external contributors, and we haven't found how to
fix this issue.

Another reason is that Pronto only detects issues in the lines where the
changes are done, but sometimes we introduce issues related to other
lines and those aren't detected by Pronto. Also, when adding or changing
Rubocop rules, or when we update Rubocop, Pronto doesn't check whether
those rules are applied in every Ruby and ERB file, and we sometimes
forget to do so (particularly in ERB files).

So, from now, the linters will check all the code in every pull request.

Note we're now excluding the `vendor` folder in our linters because the
`setup-ruby` action actions generates a `vendor/bundle/` folder with all
our gem dependencies, and we don't want to check those files.
2024-06-18 19:11:55 +02:00
Javi Martín
61a6ba26b1 Simplify dependabot condition in pronto workflow
We had the `*` because, in the past, pull request could be opened by
either dependabot or dependabot-bot. That's no longer the case since we
started using dependabot v2.
2024-06-18 19:01:31 +02:00
Javi Martín
e646689535 Rename linters workflow to pronto
We're going to add a linters workflow, so the name would be confusing.
2024-06-18 18:27:32 +02:00
Javi Martín
444b8c3390 Ignore stylelint false positive in datepicker overrides
We can't simply remove the nesting selector in this case since it's
inside a `:not` pseudo-class. Removing the nesting selector would cause
a syntax error.
2024-06-18 18:27:32 +02:00
Javi Martín
6f9de94013 Extract stylesheet for social share button styles
This way we can ignore the selector-class-pattern stylelint rule error
due to the `.ssb-whatsapp_app` selector.
2024-06-18 18:27:32 +02:00
Javi Martín
b2be64848c Ignore legislation_process nesting in stylelint
This file was generated by a different developer who ignored the nesting
rules. Refactoring it has been in our TODO list for years, but we
haven't done it yet.

Since we want stylelint to check that there are no errors after the
changes in a pull request, but we've still got errors in this file,
we're ignoring them for now.
2024-06-18 18:27:32 +02:00
Javi Martín
3d5696aff5 Apply no-redeclare ESLint rule
This rule is part of the `eslint:recommended` package. It was the only
rule we weren't following 100% of the time (other than the line length).
2024-06-18 18:27:32 +02:00
Javi Martín
5d4c5a12a8 Add ESLint as a development dependency
Since now we aren't just using ESLint in the context of a pull request
(with pronto-eslint), we're also adding the `ignorePatterns` option so
it ignores third-party files.

Note we're using ESLint 8 because ESLint 9 doesn't support our
`.eslintrc` configuration file, which we need because it's required by
pronto-eslint. However, when running pronto-eslint, we're using ESLint 6
(I think); this means that now the eslint command we run in development
and the one run by pronto might behave differently, particularly if we
add rules that have been introduced in ESLint 7 or 8. For now, since we
generated the `.eslintrc` file using ESLint 6.0.1, everything works as
expected in both situations.
2024-06-18 18:27:32 +02:00
Javi Martín
94145f4d09 Don't check ERB Lint ErbSafety in files using raw
We're excluding these files because they use `raw` to render content
than only administrators can edit, and we trust administrators not to
provide unsafe HTML. We should definitely sanitize them at some point
but, at the same time, we should also try to keep compatibility in
installations taking advantage of `raw`.

Also note that ERB Lint does not allow customizing the severity of a
linter; if it ever does, we'll use the severity rule instead of
excluding files.
2024-06-18 18:27:32 +02:00
Javi Martín
a15ff36a22 Apply Rails/SafeNavigation in officing booth view
In commit 9329e4b6e, `try` was added because there was a case where this
partial was rendered and the `current_booth` method didn't exist.
However, that's no longer the case since commit d5c7858f6. Since then,
this partial is only rendered in the officing section, where the
`current_booth` method is defined.

So we can use the safe navigation operator instead of `try`.
2024-06-18 18:27:32 +02:00
Javi Martín
db274e9a44 Apply Lint/SymbolConversion rule in ERB files 2024-06-18 18:27:32 +02:00
Javi Martín
7c1c8e0436 Merge pull request #5580 from consuldemocracy/sign_out_specs
Use logout to sign out in tests
2024-06-18 17:01:21 +02:00
Javi Martín
3e55f22d9f Merge pull request #5575 from consuldemocracy/fix_avatar_alignment
Fix avatar alignment in "my account"
2024-06-18 16:58:47 +02:00
Javi Martín
ca7983baf4 Fix avatar alignment in "my account" and users#show
In commit 35659d441, we started using an <svg> tag instead of an <img>
tag to render avatars. That meant that the `vertical-align: middle` rule
we've got for images was no longer being applied.

So we're adding it back.

The only places where this icon wasn't rendered correctly were "my
account" and the show action in the users controller. The comments were
not affected because we've got a `float: left` rule for the
`comment-avatar svg` selector, which causes the browser to ignore the
value of the `vertical-align` propertly, and the avatars showing author
information were not affected because the `.author-photo` selector
already had a `vertical-align` rule.
2024-06-17 18:19:18 +02:00
Javi Martín
9eca5b081e Merge pull request #5543 from consuldemocracy/node_js_18.20.2
Update Node.js from 18.18.2 to 18.20.3
2024-06-17 17:50:44 +02:00
Javi Martín
4ec7be12fc Update Node.js from 18.18.2 to 18.20.3 2024-06-17 17:37:06 +02:00
Javi Martín
c7267f9729 Use logout to sign out in tests
We were doing it most of the time, but in some cases we were clicking
the "Sign out" link instead. These actions aren't the same, just like
using `login_as` is not the same as visiting the sign in page and
submitting the form.

Some of these tests failed sometimes because the user wasn't signed in
after using `login_as`. One possible cause could be that we weren't
adding an expectation after clicking the "Sign out" link.

So using `logout` adds consistency, simplifies the code, and might
reduce the chance of these tests failing in the future (although they
might still fail in the future because some of these tests check the
database after a `visit` call).
2024-06-17 16:48:37 +02:00
Javi Martín
a20f32401f Add an expectation after signing out in officing spec
In this test, we were signing out after confirming a vote, but we
weren't waiting for the request to finish before using the `login_as`
method. Sometimes this test failed with a screenshot showing that the
user wasn't signed in after the `login_as` call, so this might have been
the cause.

We could use the `logout` method instead, but since we don't have any
other tests that click the "Sign out" link from the officing area, we're
leaving it as it was; we might change it to `logout` in the future if
the test keeps failing once in a while.

Note we're also replacing a `visit` call which my guess is was there
because the "Sign out" link wasn't visible due to the notice covering
it. So we're closing the notice instead.
2024-06-17 16:46:36 +02:00
Javi Martín
9018048e06 Merge pull request #5541 from consuldemocracy/ruby3.2.4
Upgrade Ruby to version 3.2.4
2024-06-17 15:43:06 +02:00
Javi Martín
118a4dde89 Upgrade Ruby to version 3.2.4
As usual, we're upgrading the parser gem so we don't get warnings about
the Ruby version when running a rails console.
2024-06-17 15:18:40 +02:00
Javi Martín
4011ec0d3c Merge pull request #5500 from consuldemocracy/remove_bullet
Remove Bullet from Gemfile
2024-06-17 15:13:08 +02:00
Javi Martín
fbc7ba78e9 Merge pull request #5547 from consuldemocracy/empty_cache_when_upgrading
Clear Rails cache when upgrading Consul Democracy
2024-06-17 15:11:00 +02:00
Javi Martín
7cb122564d Merge pull request #5577 from consuldemocracy/capybara_screenshots_path
Update screenshots path in GitHub Actions
2024-06-17 15:07:38 +02:00
Javi Martín
10d93a04d3 Clear Rails cache when upgrading Consul Democracy
We use caching in our application in two different ways:

1. Rails.cache.fetch in models/controllers/libraries
2. Fragment caching in the views

When using Rails.cache.fetch, we usually set an expiration date or
provide a precise way to invalidate it. If the code changes and the
information stored in the cache is different from what the new code
would return, it's usually not a big deal because the cache will expire
in an hour or a day. Until commit a4461a1a5, the statistics were an
exception to this rule, but that's no longer the case. The actual
exception to this rule are the i18n translations, but the code caching
them is very simple and hasn't changed for more than three years (when
it was written for the first time).

When using fragment caching, on the other hand, Rails automatically
invalidates the cache when the associated _view code_ changes. That is,
if a view contains cache, the view renders a partial, and the partial
changes, the cache is correctly invalidated. The cache isn't invalidated
when the code in helpers, models or controllers change, though, which
the Rails team considers a compromise solution.

However, we've been moving view partials (and even views) to components,
and the cache isn't invalidated when a component changes (it doesn't
matter whether the component Ruby file or the component ERB file
changes). That means that the cache will keep rendering the HTML
generated by the old code.

So, now, we're clearing the cache when upgrading to a new version of
Consul Democracy, as part of the release tasks. That way, institutions
upgrading to a new version don't have to worry about possible issues
with the cache due to the new code not being executed.

I was thinking of adding it to a Capistrano task, but that would mean
that every time people deploy new code, even if it's a hotfix that
doesn't affect the cache at all, the cache would be cleared, which could
be inconvenient. Doing it in a release, that usually changes thousands
of lines of code, sounds like a good compromise.
2024-06-17 14:48:34 +02:00
Javi Martín
baec41c43d Fix screenshots in GitHub Action when two jobs fail
The upload-artifact action does not support using the same artifact name
in different jobs (or in different matrix scenarios) since version 4,
which we started using in commit acfaada82. That meant that screenshots
were not uploaded correctly when two or more knapsack nodes failed.
2024-06-14 17:55:27 +02:00
Javi Martín
37c9e6bcde Update screenshots path in GitHub Actions
Since we upgraded to Rails 7.0 in commmit 8596f1539, the screenshots
started to be stored in `tmp/capybara`, so the step uploading
screenshots wasn't doing anything.
2024-06-14 17:50:54 +02:00
Javi Martín
cd82a05161 Merge pull request #5537 from consuldemocracy/rename_question_answer_to_option
Rename Poll::Question::Answer to Poll::Question::Option
2024-06-14 15:19:39 +02:00
Javi Martín
ca8329d5f2 Remove unused association between user and pair answers
The code for Poll::PairAnswer was removed in commit af7c37634.
2024-06-13 19:38:29 +02:00
Javi Martín
5fa6db2226 Rename HTML attributes referencing poll options
Since now poll question answers have been renamed to poll question
options, using HTML IDs, classes and data attributes named `answer` was
confusing.
2024-06-13 19:13:05 +02:00
Javi Martín
8997ed316c Rename variables describing poll options as answers
Since we've renamed the class to `Option`, having variables, methods and
texts refering to it as `answer` was confusing.
2024-06-13 19:13:05 +02:00
Javi Martín
38b38d1fcc Rename Poll::Question::Answer to Poll::Question::Option
Having a class named `Poll::Question::Answer` and another class named
`Poll::Answer` was so confusing that no developer working on the project
has ever been capable of remembering which is which for more than a few
seconds.

Furthermore, we're planning to add open answers to polls, and we might
add a reference from the `poll_answers` table to the
`poll_question_answers` table to property differentiate between open
answers and closed answers. Having yet another thing named answer would
be more than what our brains can handle (we know it because we did this
once in a prototype).

So we're renaming `Poll::Question::Answer` to `Poll::Question::Option`.
Hopefully that'll make it easier to remember. The name is also (more or
less) consistent with the `Legislation::QuestionOption` class, which is
similar.

We aren't changing the table or columns names for now in order to avoid
possible issues when upgrading (old code running with the new database
tables/columns after running the migrations but before deployment has
finished, for instance). We might do it in the future.

I've tried not to change the internationalization keys either so
existing translations would still be valid. However, since we have to
change the keys in `activerecord.yml` so methods like
`human_attribute_name` keep working, I'm also changing them in places
where similar keys were used (like `poll_question_answer` or
`poll/question/answer`).

Note that it isn't clear whether we should use `option` or
`question_option` in some cases. In order to keep things simple, we're
using `option` where we were using `answer` and `question_option` where
we were using `question_answer`.

Also note we're adding tests for the admin menu component, since at
first I forgot to change the `answers` reference there and all tests
passed.
2024-06-13 19:13:01 +02:00
Javi Martín
d1c0dda299 Remove Bullet from Gemfile
We've been ignoring what the Bullet gem reports for at least 6 years
(maybe more), but we were still updating the gem and maintaining the
code in `config/environments/` (which caused conflicts every time we run
`rails app:update` to upgrade to a new Rails version). Maintaining it
isn't a huge effort, but it's infinitely bigger than the benefits we get
from it, which are zero.

Adding `includes` everywhere we query for records would be a huge
maintenance effort and would make the code less readable, so I don't
think it's worth it. We might do it occasionally if we detect a
performance bottleneck.

We could also use a gem to automatically avoid the N+1 queries problem,
like Goldiloader [1], ArLazyPreload [2] or JitPreload [3]. Benchmarks
show that the performance improvements obtained by using these gems is
about less than 10% (it depends a lot on the page being loaded, though),
which IMHO doesn't justify adding yet another gem that patches
ActiveRecord and that could be incompatible with other gems doing so.

There are a couple of open pull requests (at the time of writing,
they've been open for about two years) in the Rails repository [4][5] to
automatically avoid N+1 queries as well. For now, we'll hope something
similar is integrated in Rails itself in the future.

[1] https://github.com/salsify/goldiloader
[2] https://github.com/DmitryTsepelev/ar_lazy_preload
[3] https://github.com/clio/jit_preloader/
[4] Pull request 45231 in https://github.com/rails/rails/
[5] Pull request 45413 in https://github.com/rails/rails/
2024-06-13 17:57:42 +02:00
Javi Martín
6188281d33 Don't use instace variables in component views
Just like we do every else (sometimes even on that very same file), we
use the method instead of the instance variable.

We're doing this change now because we're about to modify one of these
files (the poll question answers documents index component).
2024-06-12 15:16:14 +02:00
Javi Martín
bfee1b0ecb Simplify query to get possible answers
We added the code indicating the table in commit 673ec075e because back
then we had a `title` column in both the `poll_question_answers` table
and the `poll_question_answer_translations` table.

Since that's no longer the case since commit 7a7877656, we can simplify
the code.
2024-06-12 15:16:14 +02:00
Javi Martín
5a0fa28189 Remove no longer needed calls to require_dependency
Not sure about when we stopped needing them, but all usages of
require_dependency definitely become obsolete after we started using
Zeitwerk in commit 5f24ee912.

We're also going to rename `Poll::Question::Answer` to
`Poll::Question::Option`, so the conflict of having two `Answer`
classes, that made us add this code in the first place, will not even
exist.
2024-06-12 15:16:14 +02:00
Javi Martín
fd04860032 Use consistent names in poll question answer tests
We were using three different variable names for the same thing, in
consecutite tests.
2024-06-12 15:16:14 +02:00
Javi Martín
2117720c6c Merge pull request #5499 from consuldemocracy/fix_poll_styles
Fix styles for polls table and polls dates
2024-06-10 18:42:35 +02:00
Javi Martín
eef9f58410 Extract component to render poll geozones
This way we remove a bit of duplication.

These changes also affect the way geozones are rendered in a couple of
minor ways, making them more consistent:

* No empty list of geozones is rendered when there are no geozones
  (before these changes, an empty list was rendered in the index action
  but not in the show action)
* The text clarifying the geozone restriction is always shown (before
  these changes, it was shown in the index action but not in the show
  action)

We've added tests for these cases.
2024-06-10 17:11:30 +02:00
Javi Martín
ae026f0f6f Fix text providing geozone info
The text wasn't gramatically correct in English, since it had
the verb before the subject.

Since I'm not a native English speaker, I'm not sure about the
correct way to mention the Census part. I'm using "residents
in" since it sounds OK to me, but I might be wrong.
2024-06-10 16:53:29 +02:00
Javi Martín
5dc98929fc Move poll header partial to a component
This way it'll be easier to write tests for it when we change
it.
2024-06-10 16:53:13 +02:00
Javi Martín
1354239ea8 Merge pull request #5573 from consuldemocracy/remove_bin_rspec
Don't use Spring when running bin/rspec
2024-06-10 15:00:42 +02:00
Javi Martín
16008b5788 Add a note regarding CI when running the tests
Many developers run `bin/rspec` and then are (reasonably) confused when
running the tests takes too long.

So we're clarifying that running the whole test suite should be done
using a CI, and only relevant tests should be run while developing on
your machine.
2024-06-07 20:28:48 +02:00
Javi Martín
3aa75d62c4 Don't use Spring when running bin/rspec
This command wasn't working since we removed the spring-commands-rspec
gem in commit e4e0cb5d4.
2024-06-07 20:22:28 +02:00
Javi Martín
bb574db1ea Allow customizing the text to display poll dates
Since we were using `I18n.t`, our monkey-patch of the `t` helper wasn't
being applied.
2024-06-07 16:20:38 +02:00
Javi Martín
d9662164b8 Remove unused code to display polls with no dates
When this code was added, in commit 1a20a3ce4, we had no validation
rules checking the presence of the start and end dates of a poll. Now we
do, so we don't have to check this condition in the view.
2024-06-07 16:19:29 +02:00
Javi Martín
438fe7bd25 Fix inner borders in polls administration tables
The rows in these tables were using the styles from the `.poll`
selector, and the `position: relative` property defined there caused the
inner borders to disappear in some browsers (like Firefox).

So we're adding the `public` class to the selector; this way, it doesn't
affect elements in the admin section.

Even though it's only necessary to add the `.public` prefix to the
`.poll` selector in one place in order to fix this issue, we're doing it
everywhere for consistency.
2024-06-07 16:19:04 +02:00
Javi Martín
7b3b41386e Fix styles for poll dates
We accidentally introduced a typo in commit f497227e3 which caused the
dates to be rendered outside the element where the dates styles are
applied.
2024-06-07 15:52:02 +02:00
Javi Martín
08ca920819 Simplify conditions to render poll status icons
We were using a redundant `elsif` instead of an `else`. We were also
using a negative condition in the main `if`, which made the code a bit
harder to read.

Since we usually use `current_user` instead of `user_signed_in?`, we're
also changing that for consistency.Extract component to render the status of a poll
2024-06-07 15:52:02 +02:00
Javi Martín
765ab758dc Extract component to render a poll in the poll index
This is consistent with the way we've got partials to render debates,
proposals and legislation processes on their index pages.

Note that, while adding the tests for the status icon, we're keeping one
system test because it also tests the process of voting. We're adding a
new, similar component test, where the voter is created in the database,
so all possible statuses are tested in the component.
2024-06-07 15:52:02 +02:00
Javi Martín
2b03e3ebc4 Remove unused CSS to display poll status icons
This code isn't used since commit 5fdbc7b8a.
2024-06-07 15:52:02 +02:00