Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
033f3c33e3 Add SpaceAroundEqualsInParameterDefault rule
We were using it in most places, but not everywhere.
2019-10-24 17:56:03 +02:00
Javi Martín
d938077813 Remove empty lines around if and when body
Unfortunately, there doesn't seem to be a Rubocop rule for this one.
I've found these empty lines thanks to Rufo.
2019-10-24 17:56:03 +02:00
Javi Martín
9028d82f77 Remove unnecessary enconding magic comment
This comment isn't necessary since Ruby 2.0, where UTF-8 became the
default encoding.

I've found this issue thanks to the EmptyLineAfterMagicComment rubocop
rule.
2019-10-24 17:56:03 +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
Javier Martín
5cf2352739 Merge pull request #3793 from consul/dependabot/bundler/loofah-2.3.1
[Security] Bump loofah from 2.3.0 to 2.3.1
2019-10-24 17:29:20 +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
Javier Martín
b6750e8f17 Merge pull request #3792 from consul/rubocop_find_by
Apply rubocop FindBy rules
2019-10-24 16:47:21 +02:00
dependabot-preview[bot]
3ee216ba51 [Security] Bump loofah from 2.3.0 to 2.3.1
Bumps [loofah](https://github.com/flavorjones/loofah) from 2.3.0 to 2.3.1. **This update includes a security fix.**
- [Release notes](https://github.com/flavorjones/loofah/releases)
- [Changelog](https://github.com/flavorjones/loofah/blob/master/CHANGELOG.md)
- [Commits](https://github.com/flavorjones/loofah/compare/v2.3.0...v2.3.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-24 03:08:09 +00:00
Javi Martín
49e55b4dc4 Apply Rails/DynamicFindBy rubocop rule
We were already using `find_by` most of the time.

Since there are false positives related to our `find_by_slug_or_id!` and
`find_by_manger_login` methods, which cannot be replaced with `find_by`,
I'm adding it indicating the "refactor" severity.
2019-10-23 20:05:40 +02:00
Javier Martín
c9c89d244b Merge pull request #3791 from consul/fix_warnings
Fix warnings in several environments
2019-10-23 19:24:55 +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
69e3e67c85 Avoid "Overwriting existing method open" warning
In Ruby, the Kernel class defined the `open` method, which is available
for (almost) every object. So creating a scope with the name `open`
generates a warning indicating we are overwriting the existing `open`
method.

While this warning is pretty much harmless and we could ignore it, it
generates a lot of noise in the logs. So I'm "undefining" the method
before generating the scope, so we don't get the warning all the time.
2019-10-23 18:07:50 +02:00
Javi Martín
26e050b9f2 Remove redundant scopes
These scopes were already defined by the `enum :task` method.
2019-10-23 18:03:53 +02:00
Javi Martín
b0d1d00916 Fix modal text warning in answers documents spec
It looks like we get this warning if we check the dialog message. Using
`accept_confirm` the same way we do in the rest of the application
solves the problem.
2019-10-23 17:46:47 +02:00
Javi Martín
48cbb934c1 Bump parser to 2.6.5.0
This version is compatible with Ruby 2.4.9.
2019-10-23 17:46:47 +02:00
Javi Martín
13793d89c3 Fix extra parameter in have_link
The second parameter was ignored. Besides, we changed the place where
the link pointed to in commit fcbb11b2.
2019-10-23 17:46:47 +02:00
Javier Martín
794857c31c Merge pull request #3790 from consul/codeclimate_rubocop
Use rubocop 0.74 with code climate
2019-10-23 17:31:25 +02:00
Javier Martín
181163f2ab Merge pull request #3789 from consul/duplicate_rule
Remove duplicate rubocop rule
2019-10-23 16:57:33 +02:00
Javi Martín
d20af1225c Use rubocop 0.74 with code climate
It looks like rubocop 0.75 isn't available yet on code climate, and
their default rubocop version isn't compatible with our configuration.
2019-10-23 16:28:03 +02:00
decabeza
974064a742 Update icons scss to use fontawesome icons 2019-10-23 15:49:15 +02:00
decabeza
18975a3963 Add font-awesome-sass gem
Now can use all icons from https://fontawesome.com.
2019-10-23 15:49:15 +02:00
Javier Martín
b31f853bc6 Merge pull request #3780 from consul/bang_save
Apply `Rails/SaveBang` rubocop rule
2019-10-23 15:40:03 +02:00
Javi Martín
262fdd846c Remove duplicate rubocop rule
It was left by accident in commit b1b449b1.
2019-10-23 15:30:09 +02:00
Javi Martín
49c3402833 Use update! instead of update_attributes!
It's what we use almost everywhere, and it's shorter.
2019-10-23 14:39:31 +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
777fb55399 Don't try to save invalid resources
We were saving the resource after checking it was valid, but it will
always return false if the model isn't valid.
2019-10-23 14:32:42 +02:00
Javi Martín
0671c72c98 Don't halt callbacks on return false
This will be the default behaviour in Rails 5.1, and it's a much better
approach.

I've checked the code and luckily there doesn't seem to be a single
place where we could accidentally stop the callback chain by returning
false in (for example) a `before_save` callback.
2019-10-23 14:32:42 +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
b4b20e0295 Assign attributes to test invalid updates
Using `update` is a bit ambiguous; when we do it we aren't expressing
whether we expect the update operation to succeed or fail.
2019-10-23 14:32:42 +02:00
Javier Martín
0070b73304 Merge pull request #3787 from consul/fix_blank_comments_in_annotations
Fix adding blank comments to existing annotations
2019-10-23 14:09:57 +02:00
Javier Martín
3a0871d7aa Merge pull request #3784 from rockandror/improve-security-risk
Reduce security risk on remote_census_api
2019-10-23 14:01:54 +02:00
taitus
432e8233d2 Rename methods with same name 2019-10-23 10:21:50 +02:00
taitus
08957b70c2 Add Security/Eval rubocop rule to rubocop_basic.yml 2019-10-23 10:21:41 +02:00
Javi Martín
35bbd87093 Fix adding blank comments to existing annotations
We were using the `present?` method, which will always return true for a
comment object.
2019-10-23 04:28:08 +02:00
Javier Martín
7a9fefb933 Merge pull request #3707 from consul/dependabot/bundler/ancestry-3.0.7
Bump ancestry from 3.0.2 to 3.0.7
2019-10-23 01:29:42 +02:00
Javier Martín
ef6c7ee3bb Merge pull request #3286 from PierreMesure/replace-sass-by-sassc
Replace sass-rails gem by sassc-rails
2019-10-23 01:19:42 +02:00
dependabot-preview[bot]
4dbf38195a Bump ancestry from 3.0.2 to 3.0.7
Bumps [ancestry](https://github.com/stefankroes/ancestry) from 3.0.2 to 3.0.7.
- [Release notes](https://github.com/stefankroes/ancestry/releases)
- [Changelog](https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md)
- [Commits](https://github.com/stefankroes/ancestry/compare/v3.0.2...v3.0.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-22 22:32:10 +00:00
Javier Martín
b7a99a262e Merge pull request #3786 from consul/obsolete_method
Remove obsolete method to recalculate counter
2019-10-23 00:24:42 +02:00
Pierre Mesure
213903ad45 Replace sass-rails gem by sassc-rails 2019-10-22 21:59:14 +02:00
Javi Martín
985eeca21e Remove obsolete method to recalculate counter
This method isn't used since commit deffc7f8.
2019-10-22 20:51:56 +02:00
Javier Martín
d29d5ede5a Merge pull request #3764 from consul/rubocop_basic
Apply rubocop basic rules
2019-10-22 18:49:23 +02:00
Javi Martín
4699e767ec Apply Layout/SpaceAfterComma rubocop rule 2019-10-22 18:48:22 +02:00
Javi Martín
38b7307450 Use respond_to? instead of try
Usually when we use `try` we actually mean `try!`, which is the same as
the safe navigation operator. However, there are a few cases where we
actually mean to execute a method if the object responds to that method.

In those cases using `try` would actually be OK, but in order to avoid
confusion as to whether we mean to check for `respond_to?` or we mean to
use safe navigation, I'm removing all usages of `try`.
2019-10-22 17:37:51 +02:00
Javi Martín
1004ac01f8 Add and apply Style/SafeNavigation rubocop rule
We were already using it most of the time, but not always.
2019-10-22 17:37:51 +02:00
Javi Martín
6ceca143b4 Remove redundant check deleting content blocks
The `find` method raises an exception if nothing is found, so there's no
need to check if it found something.
2019-10-22 17:37:51 +02:00
Javi Martín
aace7aea02 Apply Layout/SpaceAroundOperators rubocop rule
We were a bit inconsistent when aligning equal signs vertically.
2019-10-22 17:37:51 +02:00
Javi Martín
cc76432a97 Use Time.current when freezing time
I was using Time.now because that's what Rails actually does, but we get
a warning by rubocop.
2019-10-22 17:37:51 +02:00
Javi Martín
6c45d21626 Avoid using Time.now and Date.today in zone tests
We've got a rubocop rule preventing us from using them, and the tests
are easier to read this way.
2019-10-22 17:37:48 +02:00
Javier Martín
c35546b720 Merge pull request #3749 from consul/sanitize_description
Sanitize descriptions in the views
2019-10-22 13:22:33 +02:00
Javier Martín
67fc73551d Merge pull request #3785 from consul/ruby2.4.9
Upgrade Ruby to 2.4.9
2019-10-21 22:45:40 +02:00