Commit Graph

20144 Commits

Author SHA1 Message Date
Javi Martín
148ac6dcb4 Move comment_on tests to mailer specs
These tests don't use the browser to send emails since commit e21588ec1.
However, note that this commit actually actually decreased our test
coverage somehow; since then, we're no longer testing whether we send an
email to the author after clicking the "Publish comment" button. We
might need to add a test for this in the `spec/system/comments_spec.rb`
file... but that's a story for another time.

Note we need to stub the `deliver_later` method; otherwise,
`open_last_email` would raise an exception since no email would have
been delivered.

We're moving them now because these tests use the `open_last_email`
method, and we're looking for places where using this method might
result in a flaky test when used inside a system test.
2025-03-26 16:27:08 +01:00
Javi Martín
fde5be293d Move mailer tests to the right file
These tests were testing mailer methods, but were inside a file for
system tests.

We're moving them now because these tests use the `open_last_email`
method, and we're looking for places where using this method might
result in a flaky test when used inside a system test.
2025-03-26 16:27:08 +01:00
Javi Martín
fb639a376d Move notification model tests to the right files
These tests were testing model methods, but were inside files for system
tests.

We're moving them now because these tests use the `open_last_email`
method, and we're looking for places where using this method might
result in a flaky test when used inside a system test.
2025-03-26 16:27:08 +01:00
Javi Martín
3a9263f6e6 Check flash messages in some system tests
This way it's more clear what the user experience is during the process.

Note this did not result in flaky tests, since the tests continue by
clicking links, that are only present after the request has finished.
However, we're adding expectations so we don't have to think whether the
tests could be flaky and because this way we're also testing the user
experience; it would be strange for a user if they were redirected to a
page without a flash message.
2025-03-26 16:27:08 +01:00
Javi Martín
548e282564 Don't click two places at the same time
Quoting from commit 57bda006b5:

> When clicking the button "Search", the link "newest" is already
> present, so capybara might click the "newest" link before the "Search"
> request is finished, leading to unexpected results.
>
> Checking the page to make sure the "Search" request has finished
> before clicking the "newest" link solves the problem.

We're doing the same thing for the other tests that click the "Search"
button and then clicked on a link. We're also making sure the language
selector changes before clicking it again.
2025-03-26 16:27:08 +01:00
Javi Martín
d3df20ba88 Remove call to visit in login_through_form_as_officer
In most tests calling this method, we were doing another visit right
after calling this method, so by removing this `visit` call we're making
the tests slightly faster and easier to follow.
2025-03-26 16:27:08 +01:00
Javi Martín
6c055f2713 Add missing expectations in common actions
We weren't checking that the request caused by clicking on the "Send
instructions" button had finished before continuing with the test.
Perhaps that's why this test has recently failed on our CI:

```
3) Emails Reset password
     Failure/Error: email = open_last_email

     RuntimeError:
       No email has been sent!
```

We're also adding an expectation to the `login_as_manager` method and
the methods to submit proposal and investment forms to make sure that,
when these method finish, the request finishes as well.
2025-03-26 16:27:08 +01:00
Javi Martín
8350b787f9 Add missing expectations after consecutive visits
This way we're 100% sure we won't have simultaneous requests since the
test will wait for one request to finish before continuing.

In the debates spec, we're also making sure the expectations between the
two consecutive visits are different.
2025-03-26 16:27:07 +01:00
Javi Martín
40d89ee47c Add missing expectations before calls to visit
There were many cases where we were clicking on a link or (most of the
time) a button and then calling the `visit` method. In the past, it
worked just fine because clicking on buttons usually results in non-AJAX
requests, meaning that the test waited for the request to finish before
continuing.

That's no longer the case, though. In the last few months/years (not
sure since when) we're getting sporadic failures because the test
doesn't wait for the request to finish before making another request
with the `visit` method. This sometimes results in flaky tests.

Some of these tests have recently failed in our CI. Here are a few
examples (note the numbers don't follow an order because these tests
failed in different jobs):

```
1) Admin edit translatable records Current locale translation does not
   exist For ActivePoll Shows first available fallback
   Failure/Error: expect(page).to have_content "Sondage en Français"

     expected to find text "Sondage en Français" in "Language: \n
       \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês
       brasileiro\n中文\n       Go back to CONSUL DEMOCRACY\nCONSUL
       DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy
       account\nSign out\nProposals\nDebates\nComments\nPolls\n
       Collaborative Legislation\nParticipatory budgets\nVoting booths
       \nSignature Sheets\nMessages to users\nSite content\nModerated
       content\nProfiles\nStatistics\nSettings\nProposals dashboard\n×
       \nPolls description updated successfully.\nList of polls\nPolls
       description\nCreate poll\nThere are no polls."

2) Public area translatable records Existing records Update a
   translation With valid data Changes the existing translation
   Failure/Error: expect(page).to have_field "Debate title",
                  with: "Title in English"
     expected to find field "Debate title" that is not disabled but
     there were no matches

2) Admin collaborative legislation Update Edit milestones summary
     Failure/Error: expect(page).to have_content "There is still a long
                                                 journey ahead of us"
       expected to find text "There is still a long journey ahead of us"
        in "Language: \n
        \nEnglish\nDeutsch\nEspañol\nFrançais\nNederlands\nPortuguês
        brasileiro\n中文\n       Go back to CONSUL DEMOCRACY\nCONSUL
        DEMOCRACY\nADMINISTRATION\nMenu\nNotifications\nMy content\nMy
        account\nSign out\nProposals\nDebates\nComments\nPolls\n
        Collaborative Legislation\nParticipatory budgets\nVoting booths
        \nSignature Sheets\nMessages to users\nSite content\nModerated
        content\nProfiles\nStatistics\nSettings\nProposals dashboard\n×
        \nProcess updated successfully. Click to visit\nBack\nAn example
        legislation process\nInformation\nHomepage\nDebate\nProposals\n
        Drafting\nFollowing\n1 language in use\nCurrent language\n
        English\nSummary\n    Format\n    ◢\n Milestone\nManage progress
        bars\nDon't have defined milestones\nCreate new milestone".
        (However, it was found 1 time including non-visible text.)

3) Admin collaborative legislation SDG related list create Collaborative
   Legislation with sdg related list
     Failure/Error:
       within("tr", text: "Legislation process with SDG related content") do
         expect(page).to have_css "td", exact_text: "17"
       end

     Capybara::ElementNotFound:
       Unable to find css "tr"

4) Valuation budget investments Valuate Feasibility can be marked as
   pending
   Failure/Error: expect(find("#budget_investment_feasibility_undecided"))
                  .not_to be_checked

    Capybara::ElementNotFound:
      Unable to find css "#budget_investment_feasibility_undecided"

3) Custom information texts Show custom texts instead of default ones
   Failure/Error:
     within("#section_help") do
       expect(page).to have_content "Custom help with debates"
       expect(page).not_to have_content "Help with debates"
     end

4) Admin budgets Update Deselect all selected staff
   Failure/Error: expect(page).to have_link "Select administrators"
     expected to find link "Select administrators" but there were no
     matches

3) Admin polls SDG related list edit poll with sdg related list
   Failure/Error:
     within("tr", text: "Upcoming poll with SDG related content") do
       expect(page).to have_css "td", exact_text: "17"
     end

   Capybara::ElementNotFound:
     Unable to find css "tr"

4) Admin polls SDG related list create poll with sdg related list
   Failure/Error:
     within("tr", text: "Upcoming poll with SDG related content") do
       expect(page).to have_css "td", exact_text: "17"
     end

   Capybara::ElementNotFound:
     Unable to find css "tr"

5) Admin custom images Image is replaced on admin newsletters
     Failure/Error:
       within(".newsletter-body-content") do
         expect(page).to have_css("img[src*='logo_email_custom.png']")
       end

     Capybara::ElementNotFound:
       Unable to find css ".newsletter-body-content"

6) Admin custom images Image is replaced on front views
     Failure/Error:
       within("#map") do
         expect(page).to
           have_css("img[src*='custom_map.jpg'][alt='Districts list']")
       end

     Capybara::ElementNotFound:
       Unable to find css "#map"
```
2025-03-26 16:27:07 +01:00
Javi Martín
04ccbea04e Split budget executions test
This way we avoid consecutive calls to `visit` to the same page.
2025-03-26 16:27:07 +01:00
Javi Martín
7870952dff Remove duplicate expectations in executions test
We were checking the same thing twice.
2025-03-26 16:27:07 +01:00
Javi Martín
bdc53ffe02 Remove unneeded consecutive calls to visit
This way we're 100% sure we won't have simultaneous requests which could
cause flaky tests. Besides that, we make these tests slightly faster.
2025-03-26 16:27:07 +01:00
dependabot[bot]
29ea8b9857 Bump nokogiri from 1.18.3 to 1.18.4
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.18.3 to 1.18.4.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.18.3...v1.18.4)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-26 15:15:28 +00:00
Sebastia
f06bf6b967 Merge pull request #5926 from consuldemocracy/fix-ci-tests
Use old Chrome in CI tests
2025-03-26 15:11:57 +00:00
taitus
772dc50ee4 Use old Chrome in CI tests
Our tests are failing fairly consistently on CI. We
believe that this started when the most recent Github Actions
ubuntu-latest image was released[1]. Though, we don't 100% understand
why. There's some speculation[2] that the root of the issue has
something to do with Chrome/Chromedriver version 134 (which is the
version bundled with that new ubuntu-latest).

[1]: https://github.com/actions/runner-images PR#11761
[2]: https://github.com/teamcapybara/capybara Issue#2800

We've largely copied what the signon team did to get
their CI back up-and-running[^3].

[^3]: https://github.com/alphagov/signon PR#3663

In this commit we remove the version of Chrome that the
actions/runner-images image bundles for us, so that Selenium
doesn't try to use it and install an old version of Chrome and
Chromedriver.
2025-03-19 09:50:52 +01:00
Javi Martín
8d0bf87a75 Merge pull request #5905 from consuldemocracy/dependabot/bundler/graphql-2.4.11
Bump graphql from 2.3.18 to 2.4.11
2025-03-17 16:00:24 +01:00
Javi Martín
9fa416738b Merge pull request #5918 from consuldemocracy/dependabot/bundler/rack-2.2.13
Bump rack from 2.2.12 to 2.2.13
2025-03-11 12:24:27 +01:00
dependabot[bot]
25f23a8c54 Bump rack from 2.2.12 to 2.2.13
Bumps [rack](https://github.com/rack/rack) from 2.2.12 to 2.2.13.
- [Release notes](https://github.com/rack/rack/releases)
- [Changelog](https://github.com/rack/rack/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rack/rack/compare/v2.2.12...v2.2.13)

---
updated-dependencies:
- dependency-name: rack
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-11 02:44:24 +00:00
Javi Martín
fe1a9c65ae Merge pull request #5889 from consuldemocracy/exclude_es_in_crowdin
Don't update Spanish in Crowdin
2025-03-10 13:23:32 +01:00
Javi Martín
27ce9c24b6 Exclude Spanish in Crowdin configuration
We update the texts in Spanish ourselves, just like we update the
English texts. However, every time we get a pull request to update
translations from Crowdin, we get a bunch of texts in Spanish that we
ignore.

Hopefully excluding the Spanish language will solve the issue.
2025-03-07 17:31:35 +01:00
dependabot[bot]
0777bb917f Bump graphql from 2.3.18 to 2.4.11
Bumps [graphql](https://github.com/rmosolgo/graphql-ruby) from 2.3.18 to 2.4.11.
- [Release notes](https://github.com/rmosolgo/graphql-ruby/releases)
- [Changelog](https://github.com/rmosolgo/graphql-ruby/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rmosolgo/graphql-ruby/compare/v2.3.18...v2.4.11)

---
updated-dependencies:
- dependency-name: graphql
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-07 16:19:05 +00:00
Javi Martín
c04dac38bd Merge pull request #5892 from consuldemocracy/html_indentation
Add a linter to check indentation in ERB+HTML files
2025-03-07 17:17:30 +01:00
Javi Martín
96e99ce6c8 Make HTML Beautifier fail on nesting errors
This way we're also checking mistakes like closing tags that don't match
their opening element, which we detected by manually running HTML
Beautifier with the `-e` option, and fixed two commits ago.

Note there was a false positive in the mailer layout. We don't know the
cause. Maybe closing the ERB tag right before the HTML opening tag and
the lack of other attributes on the tag made HTML Beautifier think the
tag wasn't correctly open, but on the other hand, we have the exact same
line in other layouts where HTML Beautifier works fine. We're fixing it
by adding an HTML id attribute to the element.
2025-03-07 16:56:29 +01:00
Javi Martín
b51aa31e6a Use HTML beautifier to indent ERB files
We had inconsistent indentation in many places. Now we're fixing them
and adding a linter to our CI so we don't accidentally introduce
inconsistent indentations again.
2025-03-07 16:31:08 +01:00
Javi Martín
b4b33926cf Fix HTML closing tags
In some places, we accidentally opened the same tag twice instead of
closing it, while in some other places we closed a tag without opening
it in the first place.

We've detected these issues thanks to the HTML Beautifier gem, which
we're about to start using for indentation purposes.
2025-03-07 16:02:07 +01:00
Javi Martín
291620abf7 Use tag.attributes to set conditional HTML attributes
Using an `if..else` block made the code harder to follow since the
opening tag was inside the block but the closing tag was outside it.
Moreover, it didn't work well with HTML Beautifier (a gem we're going to
introduce to manage ERB indentations).
2025-03-07 16:02:07 +01:00
Javi Martín
1389d45646 Simplify like/unlike buttons styles on small screens
Since we're now using a flex layout, the styles are more robust when we
keep the percentages below each button even on small screens.
2025-03-07 16:00:41 +01:00
Javi Martín
5e8a61adee Merge pull request #5891 from consuldemocracy/invalid_html_in_dev_settings
Fix invalid HTML caused by the dev seeds
2025-03-07 12:52:54 +01:00
Javi Martín
720a717a51 Merge pull request #5906 from consuldemocracy/dependabot/bundler/launchy-3.1.1
Bump launchy from 3.1.0 to 3.1.1
2025-03-07 00:04:30 +01:00
dependabot[bot]
50f57c2376 Bump launchy from 3.1.0 to 3.1.1
Bumps [launchy](https://github.com/copiousfreetime/launchy) from 3.1.0 to 3.1.1.
- [Changelog](https://github.com/copiousfreetime/launchy/blob/main/HISTORY.md)
- [Commits](https://github.com/copiousfreetime/launchy/compare/v3.1.0...v3.1.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-06 22:13:31 +00:00
Javi Martín
0436d75272 Merge pull request #5807 from consuldemocracy/dependabot/bundler/recipient_interceptor-0.3.3
Bump recipient_interceptor from 0.3.2 to 0.3.3
2025-03-06 19:23:47 +01:00
dependabot[bot]
74e543e2c8 Bump recipient_interceptor from 0.3.2 to 0.3.3
Bumps [recipient_interceptor](https://github.com/croaky/recipient_interceptor) from 0.3.2 to 0.3.3.
- [Release notes](https://github.com/croaky/recipient_interceptor/releases)
- [Commits](https://github.com/croaky/recipient_interceptor/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-06 18:05:54 +00:00
Javi Martín
11816f833d Use a flex layout to render participation processes lists
This way we simplify the HTML, which had some `if...else` blocks that
were hard to follow because there were opening tags inside these blocks
while the closing tags were outside these blocks.

We're also making the CSS container-dependent instead of
window-dependent. Since there are between one and three elements inside
the panel, we accomplish this by making the element with the content
take its own line if the width of the panel is smaller than 35rem.

Note we're trying to keep the layout similar to what it was; since we're
no longer using negative margins (like the ones in the `.row` selector),
the votes element now gets a width of 22.5% instead of 25%.

Also note we're using the column-gap property for flexbox because the
`flex-with-gap` mixin doesn't work so well with elements that have
borders. Since the column-gap property for flexbox is now supperted by
more than 98% of the browsers (which wasn't the case when we started
using the `flex-with-gap` mixin), the `flex-with-gap` mixin has become
obsolete.

Finally, note we're removing the `max-width: 12rem` rule in the images.
I'm not sure why we introduced this rule in the first place, and it
didn't play so well to the new layout. I considered using code like
`max-width: min(100%, 12rem)`, but, since I'm not sure why `12rem` was
there in the first place, I'm not sure whether this approach was better,
and it sure made things more complex.
2025-03-06 18:49:39 +01:00
Javi Martín
6b81799cf9 Remove redundant CSS rule
The exact same rule was already present in the block preceding it.
2025-03-06 18:27:29 +01:00
Javi Martín
b7c07e804e Remove border in proposals and debates supports
This way, it's consistent with the investments list, where we don't use
a border in the elements used for supporting or voting investments.
2025-03-06 18:26:33 +01:00
Javi Martín
1ae4caa0ef Only render successful icon on successful proposals
Not doing so made it trickier to define a flex layout, since the
icon-successful element is given a `position: absolute`, but only for
successful proposals, while for unsuccessful proposals it was taking
the standard `position: static` value.

We're also reusing the `successful?` method instead of rewriting it in
the view, and fixing a small issue where the icon wasn't displayed for
proposals having the exact needed votes (we were using `>` instead of
`>=` in the condition).

Note that legislation proposals use the method
`Proposal.votes_needed_for_success`, which is probaby a mistake caused
by copying the code from the proposal view. Fixing this issue is out of
the scope of this commit (and pull request), though.
2025-03-06 18:25:45 +01:00
Javi Martín
717d1cd2fc Use a one-line if condition in proposals index
With the multiline condition, HTML Beautifier (which we're about to
introduce in order to manage ERB indentation) gets confused. In this
context, a one-line condition is also more readable.
2025-03-06 18:25:45 +01:00
Javi Martín
53ff81dfdf Unify code applying the colors of a process
We had some duplication because the `css_for_process_header` was using
an instance variable, and so it couldn't be called from a partial where
this instance variable wasn't available.

Using a local variable and passing it as a parameter (as we should
always do) solves the issue and lets us simplify the code.
2025-03-06 18:25:45 +01:00
Javi Martín
a1352de9eb Remove duplicate external URL
The external URL is already rendered in the `investment_detail` partial,
so we were rendering it twice in the valuation area.
2025-03-06 18:25:45 +01:00
Javi Martín
064a7490c6 Remove empty and unused file
This file was added in commit 826385f65, but it was never used.
2025-03-06 18:25:45 +01:00
Javi Martín
e8184e169b Remove commented code in devise shared link
This code was commented in commit eedd91942, shortly after the project
started.
2025-03-06 18:25:45 +01:00
Javi Martín
65e3d4b6cf Fix invalid HTML caused by the dev seeds
These settings are used in links, and were generating invalid `href`
attributes that contained spaces.
2025-03-06 18:24:57 +01:00
Javi Martín
4be2336308 Merge pull request #5890 from consuldemocracy/remove_obsolete_initializers
Remove initializers no longer in Rails
2025-03-06 18:21:04 +01:00
Javi Martín
b04d36bf5d Merge pull request #5908 from consuldemocracy/upgrading_docs
Update instructions to upgrade Consul Democracy
2025-03-06 18:20:36 +01:00
Javi Martín
10a86fd5a4 Update instructions to upgrade Consul Democracy
We now strongly recommend to upgrade one version at a time and to run
the tests before and after upgrading.

Note we use a `release` branch instead of an `upgrade` branch because
we've been mentioning the `release` branch in the release notes of every
release for years.
2025-03-06 17:22:47 +01:00
Javi Martín
d8c866c5e6 Remove initializers no longer in Rails
These initializers either don't contain any code at all or contain code
that we never use. Since this was the case in most Rails applications,
they're no longer generated in new Rails applications [1].

So we're removing them as well.

[1] See pull requests 42538 and 43237 in https://github.com/rails/rails
2025-03-06 12:11:51 +01:00
Javi Martín
f1f3724365 Merge pull request #5888 from consuldemocracy/remove_bin_update_script
Remove obsolete bin/update script
2025-03-06 11:32:23 +01:00
Javi Martín
21c28bdb81 Merge pull request #5912 from consuldemocracy/dependabot/bundler/uri-1.0.3
Bump uri from 1.0.2 to 1.0.3
2025-03-05 20:05:57 +01:00
dependabot[bot]
d5fdbb9c24 Bump uri from 1.0.2 to 1.0.3
Bumps [uri](https://github.com/ruby/uri) from 1.0.2 to 1.0.3.
- [Release notes](https://github.com/ruby/uri/releases)
- [Commits](https://github.com/ruby/uri/compare/v1.0.2...v1.0.3)

---
updated-dependencies:
- dependency-name: uri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-05 18:38:54 +00:00
Sebastia
6cd10cd550 Merge pull request #5844 from consuldemocracy/remove-unused-css
Remove unused CSS
2025-03-05 16:48:05 +00:00