Commit Graph

23 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
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
Senén Rodero Rodríguez
c6190d0199 Remove roles when block or delete users
After a user assigned as a budget admin deletes their account or gets blocked by
a moderator, the application throws an exception while loading the admin
investment index page.

As an erased user is not really deleted and neither its associated roles, the
application was failing when trying to sort and administration without a
username. In this case, the application was throwing an `ArgumentError:
comparison of NilClass with String failed` exception.

As a blocked user is not deleted or its roles, the application failed when trying
to access the user name through the delegation in the Administrator. In this
case, the application was throwing a `NoMethodError: undefined method `name' for
nil:NilClass` exception.
2022-05-04 16:37:35 +02:00
Javi Martín
efb7ad9e42 Differentiate between blocked and hidden users
It was a bit confusing to press the "hide" button and then see the user
listed as "blocked". Some moderators might think they accidentally
pressed the wrong button.
2021-12-30 16:18:26 +01:00
Javi Martín
a31e73bf23 Ask for confirmation when hiding/blocking users
In the moderation section there's no clear indicator as to what the
"Hide" and "Block" buttons do and the difference between them.

Since we're using confirmation dialogs in all moderation actions except
these ones, we're adding them here as well, so the difference will
appear in the dialog.

This isn't a very good solution, though, since the confirmation dialog
comes after clicking the button and users have already been wondering
whether clicking that button will be the right choice. A better solution
would be making the purpose clear before the button is clicked, although
that's something we don't do anywhere in the admin/moderation sections.
2021-12-30 15:50:03 +01:00
Javi Martín
a5c66c7281 Use buttons instead of links to hide content
We're continuing to replace links with buttons, for the reasons
explained in commit 5311daadf.

Since we're using the admin action component, we can also simplify the
logic handling the confirmation message.

In order to avoid duplicate IDs when generating buttons to block the
same author more than once in a page, we're including the record dom_id
in the ID of the button to block an author.
2021-12-30 15:50:03 +01:00
Javi Martín
021fef07b6 Make action names to block and hide more clear
The `hide` action was calling the `block` method while the `soft_block`
action was calling the `hide` method.

Combined with the fact that we also have a `block` permission which is
used in `ModerateActions` the logic was hard to follow.
2021-12-30 15:50:03 +01:00
Javi Martín
4c8dfb6695 Use just one action to hide users
Other than removing a redundant action, we're fixing two bugs when
blocking an author using the links in the public views:

* We were always redirecting to the debates index, even if we blocked
  the author of a proposal or an investment
* We weren't showing any kind of success message
2021-12-30 15:50:02 +01:00
Javi Martín
600a2bd4c2 Use a button instead of a link to block users
We're continuing to replace links with buttons, for the reasons
explained in commit 5311daadf.

We're also adding an ARIA label since on the same page there might be
several links to block different users.
2021-12-30 15:50:02 +01:00
rhian-cs
609e58cacb Update system specs with detailed confirmation alerts 2021-12-22 12:32:47 +01:00
Javi Martín
227a5868b8 Use order links in moderation section
Using order links in this case causes an unusual interface, where we
show filter links, then information about the number of results, and
then order links.

Whether or not this makes sense needs to be confirmed with usability
tests. In any case, this is still way better than using `<select>`
fields which automatically change to a new page, since they cause
problems to keyboard users, are harder to select for touchscreen users,
might confuse screen reader users who will notice a form but no way to
submit it, and are not elements we generally use to let users choose the
order of the records.

For a more detailed explanation of these issues, check the commit
message in the commit "Use order links to sort comments and topics"
(just a few commits ago).
2021-06-28 00:15:08 +02:00
Javi Martín
55cf502e8f Fix typo in proposal notifications moderation test 2021-06-28 00:15:08 +02:00
Javi Martín
747da42972 Test the user's point of view in moderation specs
We were checking what happens in the database, but what's important is
what users experience after hiding content or blocking authors. Besides,
accessing the database in tests after the browser has started might lead
to database inconsistencies.
2021-04-15 16:27:19 +02:00
Javi Martín
a96bd6cd88 Fix typos in moderation tests
We were checking for a CSS ID selector but forgot to add the "#".
2021-04-15 16:27:19 +02:00
Javi Martín
16a8e97737 Explicitly use rack driver in moderation specs
Just like we mentioned in commit 5f0c422eb, the filter "Mark as viewed"
doesn't work properly, so here's a case where the test would fail with
JavaScript not because the test is wrong, but due to a bug. The test was
passing simplify because there was a typo in the CSS selector, which was
supposed to select an element by ID but didn't have the "#" prefix.

For now we're keeping the test as it was, but eventually we'll have to
fix the bug.
2021-04-15 16:27:11 +02:00
Javi Martín
92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00
Javi Martín
23945c2a7c Use JavaScript in tests dealing with tabs
So what we write in the tests is close to what users experience.
2021-04-07 14:41:06 +02:00
Javi Martín
b2bc4d19f5 Use JavaScript in tests opening modal dialogs
This way we reproduce the user experience in the tests, and we can make
sure modal dialogs open when we expect it.
2021-04-07 14:41:06 +02:00
Javi Martín
5f0c422eb3 Explicitly use rack driver in notifications spec
The filter "Mark as viewed" doesn't work properly, so here's a case
where the test would fail with JavaScript not because the test is wrong,
but due to a bug.

For now we're keeping the test as it was, but eventually we'll have to
fix the bug.
2021-04-07 14:32:49 +02:00
Javi Martín
7127b46d9f Use have_current_path instead of include
Using `have_current_path`, Capybara waits until the condition is true,
while using `include` the expectation is evaluated immediately and so
tests might fail when using a driver supporting JavaScript.

Besides, using `have_current_path` the error message is more readable
when the test fails.
2021-04-07 14:32:49 +02:00
Javi Martín
02981324ab Move exception tests to controller specs
System tests are used to test the application from the user's point of
view. To test for specific exceptions, particularly regarding
authorization permissions, controller tests fit better.

Another option would be to test the page displayed shows a certain text,
like "Internal server error". I'm choosing controller tests because
they're faster and we're basically testing the same scenario many times
and we've already got a test checking what happens when users access a
page raising an exception.
2021-03-31 14:42:20 +02:00
Javi Martín
155da08cf0 Use a generic name for the search parameter
This way we can use it for any model.
2020-12-04 19:57:05 +01:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00