Commit Graph

15447 Commits

Author SHA1 Message Date
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
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
Javi Martín
f4a6830a1b Add and appy RSpec/RepeatedExampleGroupBody rule
This rule is available since rubocop-rspec 1.38.0. Thanks to it, we've
found out we were testing topics behave like notifiable twice.
2020-10-25 14:23:53 +01:00
Javi Martín
40244d6411 Add and apply FactoryBot/FactoryClassName rule
This rule is available since rubocop-rspec 1.37.0. We were already
applying the same principle in the models since commit 234a5108.
2020-10-25 14:23:53 +01:00
Javi Martín
b6a095ced7 Add and apply RSpec/EmptyLineAfterExample rule
It was introduced in rubocop-rspec 1.36.0. We were already applying it
almost everywhere.
2020-10-25 14:23:53 +01:00
Javi Martín
4865cbeb59 Add and apply RSpec/ContextMethod rubocop rule
This rule is available since rubocop-rspec 1.36.0. We were already
applying it in most cases.
2020-10-25 14:23:53 +01:00
dependabot-preview[bot]
ac30f71bda Bump rubocop-rspec from 1.35.0 to 1.41.0
Bumps [rubocop-rspec](https://github.com/rubocop-hq/rubocop-rspec) from 1.35.0 to 1.41.0.
- [Release notes](https://github.com/rubocop-hq/rubocop-rspec/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop-rspec/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop-rspec/compare/v1.35.0...v1.41.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-10-25 14:23:53 +01:00
anks
9bd012f83c Hide retired proposals from related content proposals (Merge pull request #4196)
Co-authored-by: Anna Anks Nowak <matisnape@users.noreply.github.com>
2020-10-25 14:22:41 +01:00
Javi Martín
9282be80f5 Merge pull request #4168 from consul/dependabot/bundler/rubocop-0.92.0
Bump rubocop from 0.83.0 to 0.91.0
2020-10-23 14:19:55 +02:00
Javi Martín
b27d0a8e92 Add and apply ConstantDefinitionInBlock rule
This rule was added in Rubocop 0.91.0. A similar rule named
LeakyConstantDeclaration was added in rubocop-rspec 1.34.0.

Note using the FILENAMES constant did not result in an offense using the
ConstantDefinitionInBlock rule but did result in an offense using the
LeakyConstantDeclaration rule. I've simplified the code to get rid of
the constant; not sure why we were adding a constant with `||=` in the
middle of a spec.
2020-10-23 12:04:22 +02:00
Javi Martín
eb02bc756a Remove unnecessary constant declarations
The `controller` method already creates an anonymous class inheriting
from the class we pass it, so there's no need to create yet another
subclass.
2020-10-23 12:01:39 +02:00
Javi Martín
f632c5bfca Add and apply EmptyFile rubocop rule
This rule was added in Rubocop 0.90.0.
2020-10-23 12:01:39 +02:00
Javi Martín
66759d2dc0 Apply StringConcatenation rule in some places
This rule was added in Rubocop 0.89.0. However, there are some false
positives when we don't use interpolation but simply concatenate in
order to avoid long lines. Even if there weren't false positives, there
are places where we concatenate to emphasize the point that we're adding
a certain character to a text.

We might reconsider this rule in the future, since we generally prefer
interpolation over concatenation.
2020-10-23 12:01:39 +02:00
Javi Martín
efd8f47596 Add and apply ArrayCoercion rubocop rule
This rule was added in Rubocop 0.88.0.
2020-10-23 12:01:39 +02:00
Javi Martín
7275fc9aa2 Add and apply RedundantFileExtensionInRequire rule
This rule was added in Rubocop 0.88.0.
2020-10-23 12:01:39 +02:00
Javi Martín
02ecdf6acc Add and apply Style/AccessorGrouping rubocop rule
This rule was added in Rubocop 0.87.0. We were already grouping
accessors in most places.
2020-10-23 12:01:39 +02:00
dependabot-preview[bot]
e5f4869c02 Bump rubocop from 0.83.0 to 0.91.0
Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.83.0 to 0.91.0.
- [Release notes](https://github.com/rubocop-hq/rubocop/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.83.0...v0.91.0)

The `ConsiderPunctuation` option in the `OrderedGems` rule now defaults
to false. We're changing it to true so we keep the existing behavior and
because that's the way programs like vim sort lines.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-10-23 12:01:39 +02:00
Javi Martín
75fefcc2bb Merge pull request #4210 from consul/fix_rubocop_offense
Fix rubocop offenses in XLSX files
2020-10-23 11:59:31 +02:00
Javi Martín
6a1b12db4c Fix indentation in XLSX file
I'm not sure why we didn't detect it before; either Hound does not iden-
tify the file as a Ruby file, or an older version of Rubocop didn't.
2020-10-22 14:48:32 +02:00
Javi Martín
ec0e9052ab Fix extra spacing in deploy.rb
For some reason rubocop/hound didn't report it in previous versions.
2020-10-22 14:48:32 +02:00
Javi Martín
eb0de3824c Merge pull request #4193 from consul/devise_security
Bump devise-security from 0.10.1 to 0.11.1
2020-10-22 14:10:06 +02:00
Javi Martín
dfb80b08c7 Bump devise-security from 0.10.1 to 0.11.1
The original devise_security_extension gem has not been maintained for
years. Its last release was version 0.10.0, and wasn't compatible with
Rails 5, and so we were using its master branch.

Since the gem was unmaintained, it was forked as devise-security and the
aforementioned master branch was released as version 0.10.1. This
version wasn't published in Rubygems, though, so we're now using the
first version that was published in Rubygems and had a release
announment [1].

Dependabot will probably open a pull request to upgrade to the latest
version, but for now I'm trying to keep the devise-security gem as
similar as the version we were using to make sure they're compatible,
particularly considering we're monkey-patching some of the modules
provided by this gem.

[1] https://github.com/devise-security/devise-security/releases/tag/v0.11.1
2020-10-22 13:58:14 +02:00