Commit Graph

34 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
adba81ea89 Add and apply Style/RedundantSelf rubocop rule 2021-09-03 11:49:53 +02:00
Machine Learning
4d27bbebad Add experimental machine learning 2021-08-16 16:31:04 +02:00
taitus
ee66c4182a Return error when the related content already exists
It looks like this bug was introduced in commit 7ca55c4. Before that
commit, a message saying "You added a new related content" was shown,
but (as expected) the related content wasn't added twice.

We now check this case and add a slightly clearer message.
2021-06-25 17:15:34 +02:00
Javi Martín
48dc72cea9 Avoid a brakeman warning in related contents
Although it wasn't a real security concern because we were only calling
a `find_by` method based on the user input, it's a good practice to
avoid using constants based on user parameters.

Since we don't use the `find_by` method anymore but we still need to
check the associated record exists, we're changing the validations in
the `RelatedContent` model to do exactly that.
2021-06-23 23:13:58 +02:00
Javi Martín
8f20ee1a33 Move related content validation to the model
We were manually checking validation rules (like both relationable
objects are present, or they're both the same object) in the controller
and then using the `save!` method.

However, we usually use the `save` method (which checks all validations)
in a condition, and proceed depending on the result.

Now we're taking the same approach here. This means introducing a new
validation rule in the model to check whether both relationable objects
are the same, which is more robust than checking a condition in the
controller.
2021-06-23 23:13:58 +02:00
Javi Martín
915e2792fc Use self.name for same-table relations
Personally reading the class name made me take some time to realize it
was a same-table relation.
2019-10-25 19:03:14 +02:00
Javi Martín
fda53a0a2a Remove unnecessary foreign_key options
When we specify `belongs_to :author`, ActiveRecord automatically uses
`author_id` as the foreign key.
2019-10-25 19:03:10 +02:00
Javi Martín
47b2c42a1d Apply IndentationConsistency rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Angel Perez
01c1ac2b10 Replace all occurrences of ActiveRecord::Base with ApplicationRecord 2019-04-17 17:40:56 +02:00
Julian Herrero
3ba961a2d7 Use double quotes in models 2019-03-14 17:25:43 +01:00
María Checa
a1f840e8fd Added improvements to related contents 2018-01-12 18:35:15 +01:00
María Checa
1e23281c28 Fixed related content tests 2017-12-20 13:43:56 +01:00
Bertocq
cf06d5b047 Refactor related content score methods to make them easier to follow 2017-12-20 10:24:00 +01:00
Bertocq
3eecabe9a8 Prevent authors or users that already scored from scoring related content 2017-12-20 03:06:41 +01:00
Bertocq
e6a5071160 Fix typo on RelatedContentScore attribute score to value 2017-12-20 02:36:14 +01:00
Bertocq
e19153a26e Fix typo on RelatedContentsScore call to RelatedContentScore 2017-12-20 02:36:14 +01:00
Bertocq
585eb36871 Hide related content when scoring goes under threshold 2017-12-20 02:36:13 +01:00
Bertocq
d544d56722 Add correct user to RelatedContentScore on creation 2017-12-20 02:36:13 +01:00
Bertocq
2688f2a919 Add author user to related content 2017-12-20 02:36:13 +01:00
Bertocq
4d2d7c1a0a Add act as paranoid to related content, with not_hidden scope using hidden_at 2017-12-20 02:36:13 +01:00
Bertocq
f21f5ec05e Refactor Related Content Controller score methods 2017-12-20 02:36:13 +01:00
Bertocq
065b0ed3c8 Create Related Content Scores 2017-12-20 02:36:10 +01:00
María Checa
a8ca3ec5f7 Added related content one positive score by default on create 2017-12-19 20:15:29 +01:00
María Checa
7d8b5838b9 Added new related contents score method 2017-12-19 13:14:12 +01:00
María Checa
8d7509917c Prevent relationable models from being cached 2017-12-18 22:25:22 +01:00
María Checa
97f74ac531 Renamed related content times_reported column to flags_count 2017-12-18 18:21:46 +01:00
Bertocq
b02e2729e7 Rubocop style autocorrections 2017-12-16 17:59:16 +01:00
María Checa
88fc740863 Moved RELATIONABLE_MODELS from controller to model 2017-12-14 20:48:32 +01:00
Bertocq
e02f511b3a Add times_reported integer attribute to RelatedContent 2017-11-29 19:02:14 +01:00
Bertocq
04dfc98c3f Create RelatedContent model spec to check relationable destroy 2017-11-29 19:01:50 +01:00
Bertocq
03f0534b2f Add scenario to RelatedContent model spec to check opposite related content creation 2017-11-29 19:01:12 +01:00
Bertocq
a138cda364 Create RelatedContent model 2017-11-29 19:00:54 +01:00