Commit Graph

16133 Commits

Author SHA1 Message Date
Julian Herrero
0698c0ff4f Allow users to delete their own comments 2021-04-13 20:04:04 +02:00
Javi Martín
fa14976cfd Merge pull request #4442 from consul/user_search
Improve user search by email/name
2021-04-13 18:31:34 +02:00
Javi Martín
d5ee76aac2 Merge pull request #4463 from consul/fix_follow_cache
Expire cache when users follow/unfollow
2021-04-13 14:07:36 +02:00
Javi Martín
3645c333ab Expire cache when users follow/unfollow
When users followed/unfollowed a proposal or a budget investment, the
cache did not expire and so the wrong button was displayed after
reloading the page.
2021-04-13 13:52:18 +02:00
Javi Martín
d7ad1a769f Make sure users can only delete their own follows
Since we're defining abilities with cancancan and using
`load_and_authorize_resource`, we're also modifying the `create` action
for consistency.
2021-04-13 13:52:18 +02:00
Javi Martín
8a47fe3505 Avoid a brakeman security warning
Although it wasn't a real security concern because we were only calling
a `find` method based on the user input, it's a good practice to avoid
using constants based on user parameters.

Since we don't use the `find` method anymore but we still need to check
the associated record exists, we're changing the `followable` validation
in the `Follow` model to do exactly that.
2021-04-13 13:52:18 +02:00
Javi Martín
3215060e94 Merge pull request #4464 from consul/sdg_serbian_icons
Add SDG icons for Serbian (Cyrillic)
2021-04-13 13:51:32 +02:00
Javi Martín
2da74a771f Merge pull request #4465 from consul/restore_user_content
Restore all related content along when a user is restored
2021-04-13 13:48:38 +02:00
taitus
85aba8830a Allow scope :by_username_email_or_document_number search users with whitespaces 2021-04-13 10:46:31 +02:00
Javi Martín
5af4d33c14 Merge pull request #4461 from consul/fix_flaky_dashboard_spec
Fix flaky spec "Edit poll allows removing answers"
2021-04-12 17:02:56 +02:00
Javi Martín
171a40d25d Fix flaky spec "Edit poll allows removing answers"
The test was hanging sometimes on my machine, probably because we
weren't making sure the request submitting the form had finished before
visiting a new page.

In theory the spec should have been fine from a technical point of view:
since submitting the form generates a regular HTTP request (and not an
AJAX one), Capybara/Selenium/Chromedrive should wait until the request
is finished. But that doesn't seem to be the case 100% of the time;
maybe conditions change depending on previous tests.

On the other hand, from a design point of view, the spec wasn't that
fine. The main purpose of system specs is to test the way users interact
with our application, and users don't click a button and immediately
visit a different page. Instead, most users wait until they receive
feedback of their actions, and then they visit a different page.

Of course some users might visit another page without waiting. What
happens then cannot be predicted (it will depend on which request is
handled first), and so there's no point in writing a test for this case
unless there's a specific concurrency issue we'd like to check.
2021-04-12 16:40:46 +02:00
Javi Martín
08e19153d4 Merge pull request #4455 from consul/title-suggestion
Do not make suggestions for related titles on edit pages
2021-04-12 16:31:23 +02:00
Javi Martín
cc5bdef550 Merge pull request #4456 from consul/clear_backspace
Clear fields in tests before filling them in
2021-04-12 16:25:08 +02:00
Javi Martín
235e39672e Create admin user before starting a browser
Even after the previous changes, this test is still failing sometimes
(although now it fails for a different reason). We're doing this change
in order to discard it as the reason why the test is failing.
2021-04-12 16:07:13 +02:00
taitus
65f734bf3d Reduce the number of specs lines of code 2021-04-12 14:19:45 +02:00
taitus
95503f5811 Allow search User through name with whitespaces 2021-04-12 14:19:45 +02:00
taitus
ea8ce24a2a Only make suggestions for related titles for new records
Avoid show suggestions for :edit and :update actions.
2021-04-12 11:05:51 +02:00
taitus
56d3840c40 Extract to help method to fill in the data for the suggestions 2021-04-12 11:04:32 +02:00
Javi Martín
f8500cea62 Add SDG icons for Serbian (Cyrillic)
Icons obtained at the UNDP page for Serbia [1].

Thanks Dantic for the link ;).

[1] https://www.rs.undp.org/content/serbia/sr/home/sustainable-development-goals.html
2021-04-09 17:55:03 +02:00
Carlos Iniesta
67d61699b6 Restore all related content when a user is restored 2021-04-09 17:54:56 +02:00
Carlos Iniesta
712d33ef99 Small block user refactor 2021-04-09 17:54:56 +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
5538a1346b Merge pull request #4448 from consul/improve-management-investments
Improve create investments in Management section
2021-04-09 16:40:17 +02:00
Javi Martín
843f61e987 Merge pull request #4467 from consul/fix_flaky_notification_spec
Fix flaky spec "Notifications User not logged in"
2021-04-09 16:29:17 +02:00
taitus
4468cc0c04 Use image attributes concern
Reviewing the attribute concerns it has been detected that it can also be used in
this controller.
2021-04-09 16:21:00 +02:00
taitus
be6390cc71 Allow to create an investment with documents
In the Management section when creating an investment we were not passing the
document attributes, so we were never able to associate documents.

Make the nested_documentable spec compatible with the Management section.
2021-04-09 16:21:00 +02:00
taitus
ac144d172d Move document attributes to concern 2021-04-09 16:21:00 +02:00
taitus
82cd019b40 Allow to create an investment with images
In the Management section when creating an investment we were not passing the
images attributes, so we were never able to associate images.

Make the nested_imageable spec compatible with the Management section.
2021-04-09 16:20:59 +02:00
taitus
fa12528581 Make the do_login_for method accessible to other shared specs 2021-04-09 16:20:59 +02:00
taitus
7a34a338f4 Allow to create an investment with a geolocation.
In the Management section when creating an investment we were not passing the
map attributes, so we were never able to associate a geolocation.
2021-04-09 16:20:59 +02:00
taitus
c173568404 Move map_location attributes to concern 2021-04-09 16:20:59 +02:00
Javi Martín
633be9f54e Merge pull request #4471 from consul/fix_with_locale
Fix setting locale to an unavailable one in specs
2021-04-09 16:10:38 +02:00
Javi Martín
3b1072f3d1 Fix setting locale to an unavailable one in specs
When we assigned `I18n.available_locales = default_locales` in the
`ensure` block, `I18n.locale` was set to `:zh-TW`, which is not one of
the default locales.

In some cases this resulted in tests failing:

```
I18n::InvalidLocale:
  :"zh-TW" is not a valid locale
```
2021-04-09 13:00:26 +02:00
Javi Martín
b9da024d8e Fix flaky spec "Notifications User not logged in"
We had a test failing several times in GitHub Actions where a user was
still logged in even after logout.

This issue can be reproduced running:

```
rspec spec/system/moderation/proposal_notifications_spec.rb:71 \
spec/system/notifications_spec.rb:126 --order defined
```

One possible cause is a concurrency issue because the process running
the test and the process running the browser both access the same
database connection. Maybe some database operations leak between tests
due to that, particularly if the previous test accessed the database
after starting the browser as well.

A way to avoid this possible cause is setting up the database before
starting the browser with a call to `visit`.
2021-04-09 12:54:07 +02:00
Javi Martín
50deb6b353 Merge pull request #4434 from jakrzus/default_pages
rake db:seed generates default custom pages for all languages
2021-04-08 22:51:22 +02:00
jakrzus
2a7d9298d0 Update spec/lib/tasks/seed_spec.rb
small typo

Co-authored-by: Javi Martín <35156+javierm@users.noreply.github.com>
2021-04-08 21:30:15 +01:00
Jakub Krzus
8da5291d01 create seed_spec and move there custom pages specs 2021-04-08 21:20:42 +01:00
Jakub Krzus
7e669e8e39 refactor custom pages seed files 2021-04-08 19:15:06 +01:00
Jakub Krzus
f6fb88028a add all available locales to pages_spec, ensures all custom sites translations are correct, as before it would check only :fr 2021-04-08 18:48:56 +01:00
Jakub Krzus
299a05345d add conditional to accesibility.rb generator preventing exceptions when row in translation files is nul 2021-04-08 18:45:53 +01:00
Jakub Krzus
0d093d93d8 add system spec for default custom pages translations generated by seed 2021-04-08 17:00:06 +01:00
Javi Martín
03a70f4dc9 Merge pull request #4441 from consul/banner-scopes
Fix active banners in non-UTC time zones
2021-04-08 17:39:08 +02:00
taitus
85611a5103 Adding consistency for post_started_at and post_ended_at on specs
These two fields are of type Date and in some specs they are being
filled as Time or DateTime.
2021-04-08 17:23:33 +02:00
taitus
408422891e Adding consistency in banner scopes
Since the :post_started_at and :post_ended_at fields are of type Date, we check
with Date.current and not with Time.current.

This change has been caused because some test suites were failing
(https://github.com/consul/consul/runs/2170798218?check_suite_focus=true).
The code we had was causing the banners to be available a few hours earlier
or later than they should be depending on the time zone of the application.
2021-04-08 17:23:30 +02:00
Javi Martín
214bb0f9b1 Merge pull request #4443 from consul/improve-management
Avoid exceptions in Management section
2021-04-07 21:14:29 +02:00
taitus
e2138145a5 Avoid management actions when no user is selected
Many management actions only make sense if a user has been selected
beforehand.

We updated :check_verified_user method to be able to check  actions that need to
have a user selected in order to avoid exceptions.

We need this control as :only_verified_user is not restrictive enough. The reason is
that the :managed_user method used in the :only_verified_user if it does not find a
user it does an initializce (find_or_initialize_by). This causes that when we have
"skip_verification" to true, it returns this non-persisted user as "verified".

These changes affect the actions of Account, Budgets and Proposals Controller
when no user is selected.
2021-04-07 20:49:31 +02:00
taitus
b3275b5894 Add login managed user only to the specs that need it
We prepare the file to be able to include specs
that do not need to have a logged-in user.

We also took the opportunity to not execute this
line in some specs where it was not necessary.
2021-04-07 20:04:56 +02:00
Javi Martín
5f642f9ecb Merge pull request #4454 from consul/browser_tests
Use a driver supporting JavaScript in system tests
2021-04-07 14:56:25 +02:00
Javi Martín
5f5ef3ec5c Check request finishes in remote translations spec
That way we make sure the request is finished before the test finishes.
We were getting a failure in GitHub Actions because an unrelated test
executed after this one had its locale set to Spanish (just for one
test, though), and one possible explanation could be that a previous
request which changed I18n.locale was still being executed.
2021-04-07 14:41:06 +02:00
Javi Martín
eb4ee891c4 Reduce tests timeout in GitHub Actions
Sometimes a test gets stuck and and we have to wait until it times out
in order to check which files were being tested at the time.

The default timeout is six hours. I'm reducing it to one hour which
should still be plenty of time even on repositories with no knapsack
token.
2021-04-07 14:41:06 +02:00