Commit Graph

15767 Commits

Author SHA1 Message Date
Javi Martín
09a7724307 Remove blank space after footer
In commit a8537f7e1 we added a `height: 100%` rule on links inside
cards, which is great for cards in the "Featured" section of the
homepage. However, the card in the "Open processes" section of the
homepage has as many links inside as open processes, causing its height
to be 300% if there are three processes and so expanding below the
footer.
2020-11-07 12:02:45 +01:00
Javi Martín
28b282df12 Remove unused deployment configuration variables
The server_name variable isn't used since we removed the Apache task in
commit 012d5297e, db_server and config_files aren't used since we
removed the capistrano templates in that same commit, and full_app_name
isn't used since commit 94a7e13dc.
2020-11-04 16:52:43 +01:00
Javi Martín
724a3f802b Merge pull request #4218 from consul/table_icons
Use icons in admin table actions
2020-11-04 13:22:25 +01:00
Javi Martín
a1cae895ba Use the actions component to render phase actions
We forgot to include this table when refactoring in commit 738646a56.
2020-11-03 14:58:02 +01:00
Javi Martín
9794ffbbf8 Use icons in admin table actions
The planned budget investments redesign includes using icons in some
tables, so we might as well use them everywhere.

The original design used Foundation to show the tooltips. We're using
CSS in order to keep the ERB/HTML code simple. One advantage of using
CSS is we can show the tooltip on focus as well, just like accessibility
guidelines recommend [1]. On the other hand, Foundation tooltips appear
on the sides when the link is at the bottom of the page, making sure
they're visible in this case, while CSS tooltips do not. Neither CSS
tooltips nor Foundation tooltips are dismissable, which might be an
accessibility issue.

Note we aren't changing any ERB files in order to replace links with
icons; we're only changing CSS and one line of Ruby code.

[1] https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus
2020-11-03 14:58:02 +01:00
Javi Martín
8c1140a1bf Use semantic HTML classes in table actions
Note the CSS could probably be improved to avoid duplication with other
button style definitions. However, that's fine because we're going to
change the style of the links soon.

For the same reason, I haven't bothered to style every single link the
way it was until now.
2020-11-03 14:58:02 +01:00
Javi Martín
ccb7695056 Use a custom link_to method for table actions
This way we'll be able to change the behavior of these links without
changing the view nor affecting the rest of the application.
2020-11-03 14:58:02 +01:00
Javi Martín
99dad7a7b6 Don't mix links and actions in an admin table
In some tables, we had "actions", and some columns were also links
pointing to some places. Having both of them at the same time is
confusing, particularly since traditionally the links in the columns
pointed to the same place as some of the actions (although that's not
the case since commit 48db31cd).

We're still keeping links in tables which don't have an action column.
For instance, the proposals table has a "select" button which would be
harder to use if we had action buttons next to it.
2020-11-03 14:58:02 +01:00
Javi Martín
beaff17bec Merge pull request #4202 from consul/dependabot/bundler/pg_search-2.3.4
Bump pg_search from 2.3.0 to 2.3.4
2020-11-03 12:39:06 +01:00
Javi Martín
1ac8085aa9 Merge pull request #4206 from consul/svg_icons
Allow loading icons from SVG files
2020-11-03 12:26:55 +01:00
dependabot-preview[bot]
c9245ccdc5 Bump pg_search from 2.3.0 to 2.3.4
Bumps [pg_search](https://github.com/Casecommons/pg_search) from 2.3.0 to 2.3.4.
- [Release notes](https://github.com/Casecommons/pg_search/releases)
- [Changelog](https://github.com/Casecommons/pg_search/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Casecommons/pg_search/compare/v2.3.0...v2.3.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-02 18:06:05 +00:00
Javi Martín
df6b3ff3b1 Merge pull request #4199 from consul/dependabot/bundler/rollbar-3.0.1
Bump rollbar from 3.0.0 to 3.0.1
2020-11-02 18:36:50 +01:00
dependabot-preview[bot]
6ca9c7136e Bump rollbar from 3.0.0 to 3.0.1
Bumps [rollbar](https://github.com/rollbar/rollbar-gem) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/rollbar/rollbar-gem/releases)
- [Changelog](https://github.com/rollbar/rollbar-gem/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rollbar/rollbar-gem/compare/v3.0.0...v3.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-02 16:59:49 +00:00
Javi Martín
af93f135b0 Merge pull request #4146 from consul/dependabot/bundler/savon-2.12.1
Bump savon from 2.12.0 to 2.12.1
2020-11-02 17:57:30 +01:00
dependabot-preview[bot]
136b4a51dd Bump savon from 2.12.0 to 2.12.1
Bumps [savon](https://github.com/savonrb/savon) from 2.12.0 to 2.12.1.
- [Release notes](https://github.com/savonrb/savon/releases)
- [Changelog](https://github.com/savonrb/savon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/savonrb/savon/compare/v2.12.0...v2.12.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-02 16:41:22 +00:00
Javi Martín
8ae725c234 Merge pull request #4188 from rockandror/remote_census_api_spec
Refactor RemoteCensusApi spec to use a XML response
2020-11-02 12:55:22 +01:00
Senén Rodero Rodríguez
265f8dbf01 Connect to the service only when remote census endpoint is defined
Also return an invalid response when the endpoint is not defined.

This will allow to test remote web services on development environments.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
ac6260a2ef Mock remote census responses in tests using XML
By using real XML responses developers will be able to understand better
how the integration works (the data flow), and the correspondency between
`remote_census` settings and their place at a real XML response.

As `stubbed_responses` methods were removed from the model layer now the
stubbing part should be managed from the test environment code so also
added a new helper module `RemoteCensusSetup` that can be used anywhere
where we need to call the web service.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Javi Martín
8257a82f2f Use date objects when building office residences
Since the interface to select this date uses the classic multi-field
interface for day, month and year, we're transforming it into a date in
the Office::Residence initializer.

However, the factory to build an office residence does not assign the
paremeters in the initializer but using the `date_of_birth=` method, so
when doing so we need to use a date instead of a string.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
dd0f56f85f Use shorter responses and configuration for specs
By simplyfing the responses the configuration for specs can be simpler too.

We're also using more generic terms instead of the ones used in Madrid's
Census API.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
3ed4bdaff8 Return no variants when document_number is blank
Otherwise the variants returned for document_type="1" and
document_number="" will be

`["0", "00", "000", "0000", "00000", "000000", "0000000", "00000000"]`

which seems to be useless.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
93e458d46e Return invalid response when document_type or document_number are empty
Probably this case is not real for production environments where those
arguments will always be fullfilled but seems to be interesting for
testing environment where this method is being called when those
paremeters where empty.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
06dcbd699c Extract block to configure remote census in tests
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Javi Martín
b170949fc1 Merge pull request #4209 from consul/ruby2.6
Upgrade Ruby to 2.6.6
2020-11-02 11:39:23 +01:00
Javi Martín
2195bacfb3 Merge pull request #4217 from consul/staging_background
Run delayed job tasks in the staging environment
2020-10-29 15:00:32 +01:00
Javi Martín
8e64d6c1a7 Upgrade Ruby to 2.6.6
Note this version includes the Bundler gem, and so we no longer need to
install it while deploying.
2020-10-29 11:29:45 +01:00
Javi Martín
9f689c21a2 Rename filter method to filter_by
Ruby 2.6 introduces `Enumerable#filter` as an alias to
`Enumerable#select`, and so our Filterable.filter method will not work
with Ruby 2.6.

So we're renaming the method to `filter_by`, which is similar to
`find_by`. We could also change the `filter` method so if a block is
given it delegates to `Enumerable#filter`, the same way ActiveRecord
handles the `select` method, but IMHO this is easier to follow.
2020-10-29 11:29:45 +01:00
Javi Martín
09e4d2ec19 Merge pull request #4200 from rockandror/banners_collection_check_boxes_fix
Use labels for web_section_ids checkboxes texts
2020-10-28 17:49:54 +01:00
Senén Rodero Rodríguez
96a0f1f854 Group collection of checkboxes into a fieldset element 2020-10-28 16:42:57 +01:00
Senén Rodero Rodríguez
a543fa7ea2 Use labels for banner web_section_ids checkboxes so text its clickable
Now we can use the checkbox label text directly as locator at spec,
also default web_sections are created before every spec by loading
`db/seeds.rb` file so we were duplicating "Proposals" WebSection.
2020-10-28 16:42:56 +01:00
Javi Martín
83db709fff Merge pull request #4212 from consul/fix_ajax_redirect
Fix redirect when toggling visible to valuators
2020-10-28 12:34:03 +01:00
Javi Martín
01cfed8882 Hide checkbox when investments cannot be updated
We were allowing users to check/uncheck the "Visible to valuators"
checkbox even when the budget is finished and so the investments cannot
be edited. So users were still able to check/uncheck this attribute, but
the server was silently rejecting these changes.

We've considered removing the column in this case but decided to keep it
since users can already control which columns they'd like to display.
2020-10-27 17:45:43 +01:00
Javi Martín
a422e022aa Run delayed job tasks in the staging environment
We added the background role to the production and preproduction
environments in commit d0b0782c4, but forgot to add it to the staging
environment as well.
2020-10-26 18:50:38 +01:00
Javi Martín
925f04e3f3 Allow loading icons from SVG files
There are a dozen ways to add an icon used for decoration. Each of them
offers advantages and disadvantages regarding these topics:

* Accessibility
* Ease of use for developers
* Ease of customization for CONSUL installations
* Maintainability
* Resulting file size
* Number of HTTP requests
* Browser support
* Robustness

We were using one of the most common ones: icon fonts. This technique
shines in many of these aspects. However, it misses the most important
one: accessibility. Users who configure their browser to display a
custom font would see "missing character" icons where our icons should
be displayed. Some users have pointed out they use a custom font because
they're dyslexic and webs using icon fonts make it extremely painful for
them [1].

Screen reader users might also be affected, since screen readers might
try to read the UTF-8 character used by the icon (even if it uses a UTF
Private Use Area) and will react to it in inconsistent ways. Since right
now browser support for different techniques to prevent it with CSS
ranges from non-existant (CSS speech module) to limited (use an
alternative text in the `content` property [2]), we've been adding an
HTML element with an `aria-hidden` attribute. However, by doing so the
ease of customizations for CONSUL installations is reduced, since
customizing ERB files is harder than customizing CSS.

Finally, font icons are infamous for not being that robust and
conflicting with UTF settings in certain browsers/devices. Recently Font
Awesome had a bug [3] because they added icons out of the Private Use
Area, and those icons could conflict with other UTF characters.

So, instead of loading Font Awesome icons with a font, we can add them
using their SVG files. There are several ways to do so, and all of them
solve the accessibility and robustness issues we've mentioned, so that
point won't be mentioned from now on.

All these techniques imply having to manually download Font Awesome
icons every time we upgrade Font Awesome, since the `font-awesome-sass`
gem doesn't include the `sprites/` and `svgs/` folders Font Awesome
includes in every release. So, from the maintenance poing of view,
they're all pretty lacking.

Method 1: SVG sprites with inline HTML

We can use SVG files where template icons are defined, like so:

<svg>
  <use xlink:href="solid.svg#search"></use>
</svg>

This technique has great browser support and it only generates one HTTP
request for all icons. However, it requires adding <svg> tags in many
views, making it harder to customize for CONSUL installations. For
developers we could reduce the burden by adding a helper for these
icons.

Downloading all the icons just to use one (or a few) might also be
inconvenient, since the total file size of these icons will be up to a
megabyte. To reduce the impact of this issue, we could either minimize
the SVG file, compress it, or generate a file with just the icons we
use. However, generating that custom file would be harder to maintain.

Method 2: CSS with one SVG icon per file

We can use the separate SVG files provided by Font Awesome, like so:

background: url("solid/search.svg");

Or, if we want to add a color to the icon:

backgound: blue;
mask-image: url("solid/search.svg");

Using this technique will result in one HTTP request per icon, which
might affect performance. Browser support is also limited to browsers
supporting mask-image, which at the time of writing is 95% of the
browsers, with the notable exception of Internet Explorer 11.

On the plus side, using CSS makes it easy to customize and (IMHO) easy
to work with on a daily basis.

Method 3: CSS with SVG sprites

We can use the aforementioned sprites provided by Font Awesome and use
them with CSS:

backgound: blue;
mask-image: url("solid.svg#search");

The number of HTTP requests and file size are similar to Method 1, while
browser support, ease of customization and ease of use are similar to
Method 2.

There's one extra gotcha: this method requires doing minor changes to
the files provided by Font Awesome, which means this solution is harder
to maintain, since we'll have to do the same changes every time we
upgrade Font Awesome. Mainly we need to add these changes to every
sprite file:

- <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
+<!--
+This is a modified version of Font Awesome Free regular sprite file.
The icons are exactly as they originally were; the only changes are:
+
+* <symbol> tags have been replaced with <svg> tags and a <style> tag
has been added
+* A <style> tag has been added
+* The style="display:none" attribute of the main <svg> tag has been
removed
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+  <style>
+    svg svg { display: none }
+    svg svg:target { display: inline }
+  </style>

And then replace every <symbol> tag with a <svg> tag.

Method 4: CSS with Data URI

Finally, we can write the icons directly in the CSS:

backgound: blue;
mask-image: url('data:image/svg+xml;utf8,<svg...');

This method does not generate any extra HTTP requests and only downloads
the icons we need. However, maintaining it is really hard, since we need
to manually copy all the <svg> code for every icon we use, and do it
again every time we upgrade Font Awesome.

In this commit, we implement Method 2. To improve browser support, we're
falling back to font icons on browsers which don't support mask images.
So 5% of the browsers might still conflict with users changing the fonts
or with screen readers trying to announce the icon character. We believe
this is acceptable; the other option for these browsers would be to show
those icons as a background image, meaning the icons would always be
black, meaning users of these browsers would have trouble to distinguish
them if the background was dark as well.

Since we aren't sure whether the performance hit of having one HTTP
request per icon is overcome by only requesting the icons we actually
use, we aren't taking this factor into account when choosing between
methods 2 and 3. We believe this method will be the less painful one to
maintain and customize. Generating SVG sprites with just the icons we
use would increase performance, but it would make it harder for existing
CONSUL installations to use icons we haven't included in the sprites.

[1] https://speakerdeck.com/ninjanails/death-to-icon-fonts
[2] https://developer.mozilla.org/en-US/docs/Web/CSS/content#Browser_compatibility
[3] https://blog.fontawesome.com/fixing-a-unicode-bug-in-5-14-0/
2020-10-26 16:26:21 +01:00
Javi Martín
0824b64d4b Simplify display rules for show-children icon
We were using `display: inline` assuming that's the way elements will be
displayed by default when shown. However, those elements could be
displayed in a different way (inline-flex, for instance). So we avoid
any possible conflicts by using the `display: none` rule when we want to
hide the elements.

Besides, the code is now symmetrical and IMHO easier to follow.
2020-10-26 16:26:21 +01:00
Javi Martín
74e819e4e7 Use "regular" instead of "r" as parameter
Even if "r" is shorter, "regular" is easier to understand, and we're
going to store these icons in a folder named "regular", which is the
convention Font Awesome uses.
2020-10-26 16:26:21 +01:00
Javi Martín
37e7eeb6e1 Don't redirect when toggling visible to valuators
After upgrading to Turbolinks 5, redirects are followed on AJAX
requests, so we were accidentally redirecting the user after they mark
an investment as visible to valuators.

There was already a system spec failing due to this issue ("Admin budget
investments Mark as visible to valuators Keeps the valuation tags");
however, it only failed in some cases, so we're adding additional tests.

Ideally we would write a system test to check what happens when users
click on the checkbox. However, from the user's point of view, nothing
happens when they do so, and so testing it is hard. There's a usability
issue here (no feedback is provided to the user indicating the
investment is actually updated when they click on the checkbox and so
they might look for a button to send the form), which also results in a
feature which is difficult to test.

So we're writing two tests instead: one checking the controller does not
redirect when using a JSON request, and one checking the form submits a
JSON request.

I've chosen JSON over AJAX because usually requests to the update action
come from the edit form, and we might change the edit form to send an
AJAX request (and, in this case, Turbolinks would handle the redirect as
mentioned above).

Another option would be to send an AJAX request to a different action,
like it's done for the toggle selection action. I don't have a strong
preference for either option, so I'm leaving it the way it was. At some
point we should change the user interface, though; right now in the same
row there are two actions doing basically the same thing (toggling
valuator visibility and toggling selection) but with very different user
interfaces (one is a checkbox and the other one a link changing its
style depending on the state), resulting in a confusing interface.
2020-10-26 15:12:39 +01:00
Javi Martín
9920d81424 Merge pull request #4154 from consul/dependabot/bundler/rubocop-rails-2.6.0
Bump rubocop-rails from 2.3.2 to 2.6.0
2020-10-26 12:04:11 +01:00
Javi Martín
4658e18db5 Re-add and apply Rails/UniqBeforePluck rule
We removed it in commit d639cd58 because it recommended using `uniq`
where `distinct` was more appropriate. This has been fixed in
rubocop-rails 2.6.0.
2020-10-26 11:26:34 +01:00
Javi Martín
d7e6a5c6bf Add Rails/UniqueValidationWithoutIndex rule
This is something we should do everywhere because concurrent requests
might bypass Rails uniqueness validations. However, since there are
places where we aren't applying this rule and adding a unique index
means we also need to destroy any hypothetical duplicate records, it's
something we aren't going to solve right now. Therefore we use the
"refactor" severity so existing offenses don't get in our way.

In any case, we're adding the rule so we don't make the same mistake in
the future.
2020-10-26 11:26:34 +01:00
dependabot-preview[bot]
ae80fa4a1a Bump rubocop-rails from 2.3.2 to 2.6.0
Bumps [rubocop-rails](https://github.com/rubocop-hq/rubocop-rails) from 2.3.2 to 2.6.0.
- [Release notes](https://github.com/rubocop-hq/rubocop-rails/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop-rails/compare/v2.3.2...v2.6.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-26 10:53:20 +01:00
Javi Martín
bd268c3719 Merge pull request #4155 from consul/dependabot/bundler/rubocop-rspec-1.41.0
Bump rubocop-rspec from 1.35.0 to 1.41.0
2020-10-26 10:52:36 +01:00
Javi Martín
74d4fcd087 Fix RSpec/LetSetup rubocop offense
It was detected after updating rubocop-rspec.
2020-10-25 14:26:00 +01:00
Javi Martín
d2d95c8df7 Remove unused variables
Detected thanks to the RSpec/LetSetup rule after updating rubocop-rspec.
2020-10-25 14:26:00 +01:00
Javi Martín
dd7d6440ec Add and apply Capybara/VisibilityMatcher rule
This rule was added in rubocop-rspec 1.39.0. The `visible: false` option
is equivalent to `visible: :all`, but we generally use it meaning
`visible: :hidden` for positive expectations and `visible: :all` for
negative expectations.

The only exceptations are tests where we count the number of map icons
present. I'm assuming in this case we care about the number of map icons
independently on whether they are currently shown in the map, so I'm
keeping the `visible: :all` behavior in this case.
2020-10-25 14:23:53 +01:00
Javi Martín
6088334dbf Remove redundant visibility matcher usages
By default, Capybara only finds visible elements, so adding the
`visible: true` option is usually redundant.

We were using it sometimes to make it an obvious contrast with another
test using `visible: false`. However, from the user's perspective, we
don't care whether the element has been removed from the DOM or has been
hidden, so we can just test that the visible selector can't be found.

Besides, using `visible: false` means the test will also pass if the
element is present and visible. However, we want the test to fail if the
element is visible. That's why a couple of JavaScript-dependant tests
were passing even when JavaScript was disabled.
2020-10-25 14:23:53 +01:00
Javi Martín
202fe2953b Fix matchers checking elements are obscured
These tests were supposed to check the link to vote is hidden when users
don't have permission to vote. However, they aren't testing that, since
the `visible: false` option also matches visible elements. The links are
actually considered visible since they're displayed by the browser;
there's just another element on top of them.

Using `obscured: true` instead of `visible: false` solves the issue.
However, while the `obscured` option is true when the element is hidden
by another element, it's also true when the element is not currently
visible in the browser window, so in some cases we need to scroll so the
condition is effective.
2020-10-25 14:23:53 +01:00
Javi Martín
11b8561ed8 Remove unused method
It isn't used since commit d0b8fef6.
2020-10-25 14:23:53 +01:00
Javi Martín
d348e4b688 Add and apply RSpec/EmptyHook rule
This rule was added in rubocop-rspec 1.39.0. Now leaving an empty block
by accident like I did in commit 91c21b09 is harder :).
2020-10-25 14:23:53 +01:00
Javi Martín
cef54b4e59 Add and apply RepeatedExampleGroupDescription rule
This rule was added in rubocop-rspec 1.38.0. Thanks to it we've detected
we had one method tested in two different places.
2020-10-25 14:23:53 +01:00