Commit Graph

5377 Commits

Author SHA1 Message Date
Javi Martín
c8270d58bd Add and apply Rails/DurationArithmetic rubocop rule
This rule was added in rubocop-rails 2.13.0. We were already applying it
most of the time.
2022-08-24 23:24:36 +02:00
Javi Martín
5b844bf231 Use index_with to simplify hash generation
This method was introduced in Rails 6.0. It can be used to take an array
and create a hash where the elements of the array are the indexes of the
hash.
2022-08-24 18:19:02 +02:00
Javi Martín
c97e7852a4 Use "excluding" instead of "reject"
This method was already available as #without, but we didn't know about
it.
2022-08-24 18:11:56 +02:00
Javi Martín
b59e2b31d3 Use unfreeze_time instead of travel_back
This is consistent with `with_frozen_time`.
2022-08-24 18:11:56 +02:00
Javi Martín
480ab6a9da Use truncate_all instead of DatabaseCleaner
Performance tests show both methods of truncating the database take
about the same time, so we can remove one dependency and we don't lose
anything in the process.
2022-08-24 18:11:56 +02:00
Javi Martín
3d95f762af Add more expectations in SDG Management search spec
We've had some tests fail after this test was executed in our CI, and
one possible reason could be that sometimes this test finished before
all its requests had finished. This could be the case with the following
code:

```
visit sdg_management_proposals_path(filter: "pending_sdg_review")

click_button "Search"

expect(page).to have_css "li.is-active h2", exact_text: "Pending"
```

Before clicking the "Search" button, the expectation is already true, so
there's a chance that the expectation is evaluated as true before the
request has finished. That might result in requests and session data
leaking between tests.

So we're adding more expectations in order to make sure that the
requests have finished before evaluating the expectations associated to
them.
2022-08-24 17:09:12 +02:00
Javi Martín
ffc14e499a Upgrade to Rails 6.0
All the code in the `bin/` and the `config/` folders has been generated
running `rake app:update`. The only exception is the code in
`config/application.rb` where we've excluded the engines that Rails 6.0
has added, since we don't use them.

There are a few changes in Active Storage which aren't compatible with
the code we were using until now.

Since the method to assign an attachment in ActiveStorage has changed
and is incompatible with the hack we used to allow assigning `nil`
attachments, and since ActiveStorage now supports assigning `nil`
attachments, we're removing the mentioned hack. This makes the
HasAttachment module redundant, so we're removing it.

Another change in ActiveStorage is files are no longer saved before
saving the `ActiveStorage::Attachment` record. This means we need to
manually upload the file when using direct uploads. We also have to
change the width and height validations we used for images; however,
doing so results in very complex code, and we currently have to write
that code for both images and site customization images.

So, for now, we're just uploading the file before checking its
dimensions. Not ideal, though. We might use active_storage_validations
in the future to fix this issue (when they support a proc/lambda, as
mentioned in commit 600f5c35e).

We also need to update a couple of tests due to a small change in
response headers. Now the content disposition returns something like:

```
attachment; filename="budget_investments.csv"; filename*=UTF-8''budget_investments.csv
```

So we're updating regular expression we use to check the filename.

Finally, Rails 6.0.1 changed the way the host is set in integration
tests [1] and so both `Capybara.app_host` and `Capybara.default_host`
were ignored when generating URLs in the relationable examples. The only
way I've found to make it work is to explicitely assign the host to the
integration session. Rails 6.1 will change this setup again, so maybe
then we can remove this hack.

[1] https://github.com/rails/rails/pull/36283/commits/fe00711e9
2022-08-24 14:33:02 +02:00
Javi Martín
92941d3304 Keep filters in admin search
While this bug was already present in the general admin search, the
combination of both search and filters was very uncommon. I've only
found this combinations in the users section, where you've got the
"erased" filter, but in this case searching for erased users doesn't
really make sense since their username and email have been deleted and
so there's nothing to find.

So the hidden content seemed to be the only affected section. However,
we're adding the field to every section so we don't have to make sure we
add it when we need it (like we did in the SDGManagement section).
2022-08-23 14:33:55 +02:00
Jacek Skrzypacz
2af7e32415 Add search form for hidden content
Added search for comments and proposal_notifications, added tsv column
for search and rake tasks to update/create tsv vector.
2022-08-23 14:30:38 +02:00
Javi Martín
e66b9687a2 Fix calculating tsvector on hidden records
We introduced this bug in commit 55d339572, since we didn't take hidden
records into consideration.

I've tried to use `update_column` to simplify the code, but got a syntax
error `unnamed portal parameter` and didn't find how to fix it.
2022-08-23 14:30:38 +02:00
Javi Martín
3e50b7ccaf Order filters the same way in all hidden content
We were doing it differently for investments.
2022-08-23 14:30:38 +02:00
Sebastia
c33aa1d62c Merge pull request #4839 from consul/comments_count_investment
Add comments count on budget investments
2022-08-22 18:52:06 +02:00
decabeza
5b97e85dd7 Hide comments when allegations phase is closed
Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
Co-Authored-By: Javi Martín <javim@elretirao.net>
2022-08-19 18:12:49 +02:00
Javi Martín
711e6c16eb Load annotations through the draft version
We were ignoring the draft version param when loading an annotation,
which could result in a strange situation where we load an annotation
and a draft version different than the one it belongs to.

Thanks to this change, we can simplify the code a little bit. IMHO the
`comments` and `new_comment` routes should have been added on member
instead of on collection, which would further simplify the code. I'm
leaving the routes untouched just in case changing the URL has side
effects on existing installations.
2022-08-19 17:40:50 +02:00
taitus
9f90125fa7 Add attribute anchor to link
Anchor needs to be added to the link to redirect directly to the comments section.
2022-08-19 15:40:51 +02:00
taitus
2865ee286f Add comments count component
Remove all the translations that are left over after having unified them
in the component.
2022-08-19 15:40:51 +02:00
decabeza
10cd182774 Add more images to admin site customization 2022-08-17 13:51:13 +02:00
Javi Martín
11bed74678 Extract constant to configure valid mime types
This way it'll be possible to overwrite the valid mime types in a custom
model.
2022-08-17 12:56:55 +02:00
Javi Martín
00ea1bf719 Fix customization of budget_execution_no_image
We forgot to change the line rendering the image in commits 3574bf867c
and 810bdae37a, and so the custom image was being ignored.

Note that, in the test, we're stubbing a constant instead of adding a
new image. The main reason is that, if we add a new image, forks would
have to change the image when they change the `VALID_IMAGES` constant;
otherwise the tests would fail.
2022-08-17 12:53:00 +02:00
decabeza
52e65ba031 Add comments count on budget investments 2022-08-02 13:40:48 +02:00
Senén Rodero Rodríguez
0ccfac76ad Remove Processes link on help page when legislation is disabled 2022-07-20 20:44:25 +02:00
Javi Martín
6c852e3ea0 Merge pull request #4858 from consul/spacing_fixes
Fix Rubocop convention offenses
2022-06-13 19:07:39 +02:00
Javi Martín
582498428f Merge pull request #4856 from consul/digest_spec
Disable JavaScript in notification digest spec
2022-06-13 19:06:11 +02:00
Senén Rodero
ce918e70bc Merge pull request #4696 from consul/set_request_locale
Enable the `Rails/I18nLocaleAssignment` cop to scan all the application ruby files
2022-06-13 18:43:35 +02:00
Javi Martín
7e663f8bcf Fix spacing issues after removing lines
Rubocop was complaining about a Layout/ExtraSpacing in a couple of
places.

These issues weren't detected by Pronto because they didn't affect lines
changed in the pull request. These lines were fine until we removed the
lines next to them in commits 4b42a68b6 and 00f0c4410.
2022-06-13 17:39:53 +02:00
Javi Martín
8f7a3bfb35 Disable JavaScript in notification digest spec
This test has been failing many times because it checks the database
after starting the process running the browser.

We're disabling JavaScript like we do in every other test using the
`create_proposal_notification` method. This way, Capybara will use the
rack driver and there'll be no risk of errors that currently might take
place if both the process running the browser and the process running the
test access the database.
2022-06-13 17:39:21 +02:00
Julian Herrero
b9ec40325c Fix link to comments on admin view for debates 2022-06-13 17:04:51 +02:00
Senén Rodero
845f12879a Merge pull request #4850 from consul/changing_language_text_direction
Disable Turbolinks for languages with different text direction
2022-06-08 14:00:09 +02:00
Senén Rodero
494f1de80b Merge pull request #4837 from joaoGabriel55/fix_bug_when_creating_admin_tags
Fix bug when creating admin tags
2022-06-08 13:57:01 +02:00
Senén Rodero Rodríguez
64278c663c Do not exclude spec_helper.rb from Rails/I18nLocaleAssignment cop
Use the around action to set the desired locale so we do not break the rule.
2022-06-08 12:21:41 +02:00
Senén Rodero Rodríguez
ede6a3f73f Disable Turbolinks page loading for language links
Only when the current language has a different text direction
than the localization link to generate.
2022-06-08 07:12:29 +02:00
Iraline
5eb2dc5a9c adding limitation to not save blank email in model 2022-06-07 14:17:37 -03:00
Javi Martín
9938ab0017 Merge pull request #4849 from consul/more_browser_tests_database
Reduce conflicting queries/requests in system tests
2022-06-07 13:48:57 +02:00
joaoGabriel55
e767350314 Fixed bug when creating admin tags
Minor fix

Implemented specs for tags_controller and tag model

Code review
2022-06-07 08:43:27 -03:00
Javi Martín
5c1da85dca Merge pull request #4848 from consul/banner_destroy_notice
Add notice after destroying a banner
2022-06-07 11:31:06 +02:00
Javi Martín
9127e562b7 Merge pull request #4845 from consul/installation_processes
Describe enabled processes in the consul.json URL
2022-06-06 13:19:31 +02:00
Sebastia
77825ed13f Merge pull request #4818 from consul/emails_styles
System emails design
2022-06-03 08:40:54 +02:00
Javi Martín
d91775b4aa Make database queries before starting the browser
When we perform database queries in tests after the process running the
browser has started, we sometimes get failures in our test suite due to
both the tests and the browser accessing the database at the same time.
2022-06-02 19:25:14 +02:00
Javi Martín
0dded3fa22 Remove redundant expectations in polls tests
Furthermore, using `Poll.all` results in a database query, and doing so
after the process running the browser has started might result in
failures when running our test suite.
2022-06-02 19:25:14 +02:00
Javi Martín
9a8536b1fc Avoid simultaneous requests in moderation test
We were clicking on the "Sign in" link right after clicking on the "Sign
out" link, which might result in simultaneous requests and exceptions
when running our test suite.

So we're adding an expectation to make sure the first request has
finished before starting the following one.
2022-06-02 19:25:14 +02:00
Javi Martín
2d693328dc Simplify checking map longitude and latitude
We were doing a `mappable.map_location` call in an `expect` which might
result in a database queries. Doing database queries in a test after the
process running the browser has started might result in exceptions while
running our test suite.
2022-06-02 19:25:14 +02:00
Javi Martín
4318b371b0 Add expectations after submit in attachments specs
There were cases where we clicked the button to submit the form and
immediately we visited a different page.

In the past, we've had similar code produce PG::ProtocolViolation errors
in similar situations. Since we've had these errors a few times in the
nested imageable specs, there's a chance they're related to the absence
of the expectation.

Although I'm not even remotely sure this will fix these issues, at least
we now follow the convention of making expectations after every request.

Note we're changing both the nested imageable and nested documentable
specs. Only the nested imageable would need to be changed because it's
the one where there's a `visit` inside the
`imageable_redirected_to_resource_show_or_navigate_to` method. I'm
changing both for consistency.
2022-06-02 19:20:40 +02:00
Javi Martín
d4c62e2fc6 Add notice after destroying a banner
We were missing a notice in this case. Not only this caused
inconsistencies in the user experience, but it also made it hard to add
an expectation in the test checking the request had finished before
making a new one. Simultaneous requests sometimes cause failures in our
test suite.
2022-06-02 19:05:02 +02:00
Javi Martín
201e23da3d Describe enabled processes in the consul.json URL
The idea to show the status of the existing features was done in commit
7339a98b74. Back then, we didn't have the separate `process.` prefix,
and so processes were enabled/disabled using settings like
`feature.debates` instead of `process.debates`.

IMHO making the information about the enabled features public could
potentially be a bit risky since it gives too much information about the
current status of the application.

Showing which processes are enabled, on the other hand, is pretty
harmless, and it's the reason why this feature was added in the first
place.
2022-06-02 17:10:38 +02:00
Javi Martín
954bc61014 Merge pull request #4815 from iraline/fix_confirmation_token_2746
Fix Confirmation Token to only work once
2022-06-02 15:23:47 +02:00
taitus
12ea724474 Fix evaluation comment email on system emails
Currently with both seeds and dev_seeds, not only was this email not
displayed from the system emails section, but it also caused an error in
the application.

@email_to had an empty value and in the view we tried to access
@email_to.name which caused the error. We kept the same logic but
added the current_user to make sure it always has a valid value. We add
the current_user because the current_user is always present in this controller..
2022-06-02 11:24:19 +02:00
Javi Martín
cd3b196a04 Make it clear what verified users can vote for
"Participate in the final voting" was a concept which was hard to
understand since many people would think it was related to the
voting/polls section and that somehow there was going to be a "final"
poll.

So we use "Vote for budget projects" instead.

Thanks Pomerange for the suggestion.
2022-06-01 14:27:33 +02:00
Javi Martín
92b1e53fc3 Unify user permission texts
We had the same texts four times, with slight variations in the case of
the management section.

We're unifying them under the "verification" i18n namespace, since the
texts are about actions which can be done depending on whether users are
verified or not.

Note the names of the i18n keys aren't very consistent, since we use
"debates" in plural but "proposal" in singular. We're leaving it like
this so existing translations aren't affected.
2022-06-01 14:27:33 +02:00
Javi Martín
ca4a0bd4b2 Use "login details" instead of "credentials"
As suggested by Pomerange, "credentials" also refers to academic
qualifications, and so might be confusing.
2022-06-01 14:27:33 +02:00
Javi Martín
541c434e7d Fix show/hide recommendations text
As suggested by Pomerange; "proposals" sounded strange as an adjective.
2022-06-01 14:27:33 +02:00