Commit Graph

19 Commits

Author SHA1 Message Date
Javi Martín
5ff66f96cd Use file_validators to validate attachments
We were using custom rules because of some issues with Paperclip. These
rules work fine, but since we're already using the file_validators gem,
we might as well simplify the code a little bit.
2022-02-23 18:43:48 +01:00
Javi Martín
b52ceb2c78 Move attachable methods from helpers to models
We were using helper methods inside the model; we might as well include
them in the model and use them from anywhere else.

Note we're using a different logic for images and documents methods.
That's because for images the logic was defined in the helper methods,
but for documents the logic is defined in the Documentable concern. In
the past, different documentable classes allowed different content
types, while imageable classes have always allowed the same content
types.

I'm not sure which method is better; for now, I'm leaving it the way it
was (except for the fact that we're removing the helper methods).
2021-09-11 17:05:00 +02:00
Javi Martín
d14f6691dc Return document max file size in megabytes
The same way it's done for images.

We were converting the number of megabytes to bytes and then converting
it to megabytes again. Instead, we can leave it as it is and only
convert it to bytes when necessary (only one place).
2021-09-11 17:05:00 +02: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
95a90b1895 Simplify method to calculate document max size
Since we're only doing the convertion from bytes to megabytes in one
place, IMHO adding an extra method makes the code harder to read.

This way we don't have do include the DocumentsHelper in the specs
anymore, reducing the risk of possible method naming collisions.
2020-04-16 12:08:09 +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
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
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
Angel Perez
bdda397bf1 Use new RSpec stub syntax to fix deprecation warnings 2018-09-10 11:41:20 -04:00
Bertocq
44aeb7528d Fix line lenght issues on spec files 2018-02-15 23:21:03 +01:00
Bertocq
34bb9d65b1 Enable RSpec/NotToNot cop and fix all issues
Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/NotToNot
2018-01-07 17:39:48 +01:00
Bertocq
ed16a78f42 Enables RSpec/ExampleWording and fixes all issues
Both avoiding 'should' and repiting 'it' on the tests description
improves reading them and also makes all descriptions consistent.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording
2018-01-07 01:03:45 +01:00
Senén Rodero Rodríguez
824dd26d5a User new direct uploads controllers action on documentable. Skipped spec. 2017-09-26 13:55:51 +02:00
Senén Rodero Rodríguez
c6dabedb4a Add missing image model spec. Add shared specs to check image validations at any imageable model 2017-09-26 13:55:03 +02:00
Senén Rodero Rodríguez
8e91bbe5b5 Fix document validations specs 2017-08-25 18:34:53 +02:00
Senén Rodero Rodríguez
92e8468e89 Use documentables helper method within specs and document model. 2017-08-25 18:34:50 +02:00
Senén Rodero Rodríguez
3a7c9d9f83 Add documentables helper 2017-08-25 18:34:49 +02:00
Senén Rodero Rodríguez
38d4d59241 Add arguments to documentable concern to make it configurable for any recipient model. 2017-08-25 17:27:37 +02:00
Senén Rodero Rodríguez
34d06dad04 Add document model validations and model shared specs. 2017-08-25 17:27:37 +02:00