Commit Graph

114 Commits

Author SHA1 Message Date
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
5b6de96241 Add and apply MultilineMethodCallIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Javi Martín
09c63e354c Add and apply Layout/DotPosition rule
Since IRB has improved its support for multiline, the main argument
towars using a trailing dot no longer affects most people.

It still affects me, though, since I use Pry :), but I agree
leading dots are more readable, so I'm enabling the rule anyway.
2023-08-18 14:56:16 +02:00
Javi Martín
d6b85a038c Allow regular expressions in postal codes
Programmers can take advantage of this feature when defining custom
default settings. And, since many CONSUL installations had custom
changes in the `custom/verification/residence.rb` model and those
changes might use regular expressions, we're making it easier to migrate
that code to the new system to define valid postal codes.

We aren't documenting this feature in the description in the admin
section because most administrators don't know what regular expressions
are.

Note that, in order to simplify the setting, we already define the `/\A`
and `\Z/` characters. So, if the custom code had something like
`postal_code =~ /^280/`, the setting would have to be "280*" (without
the quotes) or, in order to comply with a length validation,
"280[0-9]{2}" (without the quotes).
2021-12-16 23:58:40 +01:00
Javi Martín
c2e95f6b86 Allow any postal code by default
Due to the way Madrid handled postal code validations (see issue 533),
by default we were requiring everyone to validate against the local
census *and* to specify valid postal codes.

This could be useful in some cases, but in other cases, the census
validation will be enough and there'll be no need to manually define the
valid postal codes. Besides, some CONSUL installations are used in
organizations or political parties where the postal code validation
doesn't make sense.
2021-12-16 13:57:00 +01:00
Javi Martín
35e0477e03 Ignore trailing spaces in postal codes verification
This way both administrators and regular citizens have a certain margin
of error when entering the postal codes.
2021-12-16 13:57:00 +01:00
Javi Martín
5cc10cbadf Allow dashes in postal codes
In some countries, postal codes are defined with a dash in the middle,
so we're using a colon to define ranges instead. We could also use two
dots, like in Ruby ranges, but IMHO this would cause typos since people
would enter codes separated with three dots or just one dot.
2021-12-16 13:57:00 +01:00
Javi Martín
b8b4336266 Compare postal codes with strings and not integers
We can now get rid of the rule forcing a length of 5 digits, which
doesn't apply to all countries.
2021-12-16 13:57:00 +01:00
Javi Martín
edc56b1e1f Avoid using eval in postal code validation
We were getting a warning by Rubocop because we were using eval with a
string defined by administrators, which in theory could be dangerous.
2021-12-16 13:57:00 +01:00
Javi Martín
006269a94b Simplify tests validating postal codes
We weren't using the `be_valid` matcher because we had errors in the
census data.

Removing the `before_validation` callback and using a method to get the
census data instead allows us to stub the `census_data` method in the
tests, and so we can use the `be_valid` matcher instead of calling
`valid?` manually and then checking for errors.
2021-12-16 13:57:00 +01:00
Laura Concepción Rodríguez
f4512b2117 Redefine postal code verification methods to use setting config parameter 2021-12-16 13:57:00 +01:00
Javi Martín
65c9786db7 Apply Layout/RedundantLineBreak rule to short lines
We're not adding the rule because it would apply the current line length
rule of 110 characters per line. We still haven't decided whether we'll
keep that rule or make lines shorter so they're easier to read,
particularly when vertically splitting the editor window.

So, for now, I'm applying the rule to lines which are about 90
characters long.
2021-09-03 11:49:53 +02:00
Javi Martín
8ae138aa19 Add and apply Rails/WhereNot rubocop rule
We simplify the code a little bit, and make it more consistent since we
were already using `where.not` in most places.
2021-08-09 23:52:47 +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
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
93c6347b45 Apply Rails/FindBy rubocop rule
We were already using it in most places.
2019-10-23 18:29:09 +02:00
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
Javi Martín
431074c99f Add save! method to ActiveModel models
This way we make it clear we expect records to be valid when we save
them, just like we do with ActiveRecord models.
2019-10-23 14:32:42 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
taitus
6e62ea81a9 Add new model presence validates
- Only validate :date_of_birth and :postal_code presence when the
  application has configured Remote Census and their alias fields
  has values.
2019-07-29 13:10:09 +02:00
taitus
c0c967b961 Create Management::Document initialize
Allow parse :date_of_birth on Management::Document initialize
2019-07-29 13:10:09 +02:00
taitus
bc36c5a987 Allow to Management::Document works with CustomCensusAPI
- Allow receive new fields :date_of_birth and :postal_code
- Send new fields to CensusCaller call method to allow use
  on RemoteCensusAPI
2019-07-29 13:10:09 +02:00
taitus
a382f7c301 Update all CensusCaller calls with new arguments. 2019-07-29 13:10:09 +02:00
taitus
4f52d8bf76 Verification::Residence allow to use new RemoteCensusAPI
Verification::Residence allow send params :date_of_birth and
:postal_code to CensusCaller 'call' method.
2019-07-29 13:10:09 +02:00
Julian Herrero
3ba961a2d7 Use double quotes in models 2019-03-14 17:25:43 +01:00
Bertocq
633cc1283b Fix Date & DateTime parsings to use default timezone
Date.new(...) does not take into account the current timezone, while other
parts of the application do. By default always parsing any date with the
default timezone and converting the resulting Time to Date would prevent
this kind of issues

DateTime.parse(...).in_time_zone gives an unexpected result, as the
DateTime.parse(...) will create a DateTime with +0000 time zone and the
`in_time_zone` will modify the DateTime to adjust to the default zone.

Maybe its better explained with an example, using 'Lima' as timezone:

DateTime.parse("2015-01-01")
> Thu, 01 Jan 2015 00:00:00 +0000

DateTime.parse("2015-01-01").in_time_zone
> Wed, 31 Dec 2014 19:00:00 -05 -05:00

And that's not the desired date but the previous day!
2018-04-04 14:21:39 +02:00
María Checa
d576fd5951 Merge branch 'master' into 1725-census_local_copy_user_verification 2017-07-14 15:50:26 +02:00
Bertocq
69f4e1c683 Fix all rubocop Metrics/LineLength issues (140+) 2017-07-10 13:22:49 +02:00
María Checa
089c690b49 Created new entry point CensusCaller
Here's a better alternative than the first one. Added a new abstraction level from which are performed both types of census calls, while the logic of those is managed in their own library.
2017-07-10 12:22:30 +02:00
María Checa
7e701db608 Added new census data source to Verification::Residence
Adapted model to perform a query to find a `LocalCensusRecord` record in case the census API is not available or returns invalid data.
2017-07-08 20:39:05 +02:00
Bertocq
2888c20489 Fix all Style/RedundantSelf rubocop issues 2017-07-05 11:55:52 +02:00
Bertocq
97d7a21791 Fix all Style/RedundantReturn rubocop issues 2017-07-05 11:55:52 +02:00
Bertocq
2fa92937d2 Fix all Style/BracesAroundHashParameters rubocop issues and remove them from rubocop_todo list 2017-06-28 14:12:51 +02:00
Bertocq
d7b8777395 Fix all Layout/SpaceAroundEqualsInParameterDefault rubocop issues from rubocop_todo list 2017-06-26 18:03:40 +02:00
Bertocq
8d84ed712a Fix all Rails/Validation rubocop issues and remove files from rubocop_todo list 2017-06-25 15:46:46 +02:00
Bertocq
02524b164a Rubocop autocorrections (indentations, revers unless to if, extra spaces) 2017-06-08 12:14:35 +02:00
Juanjo Bazán
590a7bce44 reassigns erased user votes when returning user is verified 2017-02-09 20:20:30 +01:00
kikito
386a5aa941 Fixes typos 2017-02-03 16:08:58 +01:00
kikito
ba87eaa47c Moves Age calculation to a module instead of monkeypatching Date 2017-02-03 15:35:41 +01:00
kikito
95f80651b1 uses Date#age_in_years when calculating ages 2017-02-03 12:56:40 +01:00
Juanjo Bazán
e2118f701b removes hardcoded age, favours setting 2017-01-09 16:05:27 +01:00
rgarcia
6b0f8eb62b do not allow verification of deregistered accounts 2016-12-12 19:11:00 +01:00
rgarcia
b12c8d3a5d validates document uniqueness only for active accounts 2016-12-12 19:11:00 +01:00
kikito
f0b8cfd4a2 Time.now -> Time.current 2016-11-23 19:19:19 +01:00
Andrés Pereira
24a9d77e64 Custom folder structure: verification residence for Madrid 2016-05-31 19:57:37 +02:00
kikito
92ecd7c983 replaces length 9 validation by format validation: only numbers, spaces and plus sign allowed 2016-04-13 19:27:04 +02:00
kikito
005bd26965 does not require phones to be Spanish any more 2016-04-13 18:52:53 +02:00