Commit Graph

14525 Commits

Author SHA1 Message Date
Javier Martín
86c00245ec Merge pull request #3801 from consul/refactor_shared_partial
Use the shared partial to render errors
2019-10-25 15:46:41 +02:00
Javi Martín
8ff728ee83 Use the shared partial to render errors
We were using it most of the time, but in some places we still had
duplicated code.
2019-10-25 15:15:47 +02:00
Javier Martín
ed15b3730c Merge pull request #3796 from consul/rubocop_rails
Apply rubocop Rails rules
2019-10-24 21:46:19 +02:00
Javi Martín
2fd79de068 Remove unneeded Rails/Exit rubocop rule
I don't think we need it because I've never seen it in our Rails
application.
2019-10-24 21:20:18 +02:00
Javi Martín
6214bda941 Move already in use Rails rules to basic cops
We were already applying the FindEach rule since commit cae210c1, while
the EnumUniqueness rule is essential when we use `enum`, and the
EnvironmentComparison rule is very useful since it forces us to use a
format the UnknownEnv rule will recognize.
2019-10-24 21:20:18 +02:00
Javi Martín
df959b74f6 Make migrations reversible
While I don't use this feature, there are developers who do. It's useful
when running migrations and changing branches.

I'm raising an `ActiveRecord::IrreversibleMigration` exception in every
`drop_table` migration because these migrations were all done before
version 1.0.0, and so making all of them reversible would be too much
work for little benefit.
2019-10-24 21:20:17 +02:00
Javi Martín
a9359fd570 Add rules related to migrations
These are rules we can't apply to existing migrations, so I'm excluding
migrations in the affected years from this check. However, we should
probably add timestamps columns and default values in non-null columns
to at least some of the tables which don't have them.
2019-10-24 21:20:17 +02:00
Javi Martín
91a3184281 Simplify creating timestamps in migrations
We were using the `timestamps` method most of the time, but sometimes we
were creating the columns manually.

Note editing past migrations if fine as long as the SQL they generate
remains identical, which is the case here.
2019-10-24 21:20:16 +02:00
Javi Martín
55addaa58a Apply rubocop rules to migration files
There are some rules which only affect migration files, and we cannot
enable them if we're excluding those files from being inspected.

We're also changing migrations related to the Rails/TimeZone rule
slightly because these fields were already changed afterwards, so we
aren't changing the schema.
2019-10-24 20:35:13 +02:00
Javier Martín
b8abf52836 Merge pull request #3797 from consul/use_block_in_travel
Use a block to travel in time in specs
2019-10-24 20:10:32 +02:00
Javi Martín
aac23ea596 Use a block to travel in time in specs
If we don't use a block, if the spec fails the `travel_back` method
isn't executed.
2019-10-24 19:24:22 +02:00
Javier Martín
00145d54ca Merge pull request #3795 from consul/rubocop_empty_lines
Add and apply rubocop rules for empty lines
2019-10-24 18:41:51 +02:00
Javi Martín
57ef380379 Add and apply Layout/ExtraSpacing rubocop rule 2019-10-24 18:11:58 +02:00
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
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