Commit Graph

186 Commits

Author SHA1 Message Date
Javi Martín
fb0c087f95 Add and apply Rails/WhereRange rubocop rule
This rule was added in rubocop-rails 2.25.0. Applying it allows us to
simplify the code a little bit. For example, now there's no need to
specify the `proposals` table in proposal scopes, which was actually
causing a bug in the `Legislation::Proposal` model, which was using the
`proposals` table instead of the `legislation_proposals` table (but,
since we don't use this scope, it didn't affect the application).
2024-07-05 17:11:29 +02:00
Javi Martín
5df7b702ee Remove visit_id from the debates table
This was added in commit 02f19aa4b, before we started tracking events.
I don't think we ever used it; in any case, we now use the `Ahoy::Chart`
class to deal with the stats Ahoy used to generate.
2024-05-09 14:56:25 +02:00
Javi Martín
f8c97b9bb9 Remove monkey-patch of the Numeric class
This monkey-patch doesn't seem to be working with Zeitwerk, and we were
only using it in one place, so the easiest way to solve the problem is
to remove it.

Note that, in the process, we're changing the operation so `* 100`
appears before the division, so it's consistent with other places where
we do similar things (like the `supports_percentage` method in the
proposals helper).
2024-04-11 19:08:01 +02:00
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
1d7a269408 Use a transaction when registering a vote
Otherwise it would be possible to increment the votes counter without
actually introducing the vote.
2023-08-30 14:46:34 +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
fa3781059c Remove URL methods in models
We can use `polymorphic_path` since commit ff93f5a591.
2021-12-30 14:45:48 +01:00
Javi Martín
4631633adf Simplify displaying debate length validation error
Adding the error to the translation means Rails will automatically show
the error message in the view.

We're also adding a test to make sure the error message is correctly
displayed.

We now have duplication in the validation rules, however. Validating
translatable attributes is still a bit of mess.
2021-10-06 14:46:30 +02:00
Javi Martín
1cecce1bc8 Fix Style/RedundantInterpolation rubocop offense
It was accidentally added in commit 713ae540b.
2021-09-03 11:49:53 +02:00
efgalvao
713ae540b0 Add length validation for debate description
Fixes issue #4013.
2021-08-29 01:13:48 +02:00
Javi Martín
b5220effd1 Bump ahoy_matey from 1.6.0 to 3.2.0
Bumps [ahoy_matey](https://github.com/ankane/ahoy) from 1.6.0 to 3.2.0.
- [Release notes](https://github.com/ankane/ahoy/releases)
- [Changelog](https://github.com/ankane/ahoy/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ankane/ahoy/compare/v1.6.0...v3.2.0)

---
updated-dependencies:
- dependency-name: ahoy_matey
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-15 01:26:29 +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
42699275a1 Add relations between relatable models and SDGs
Note we cannot directly get all related SDGs through SQL because they're
spread through different tables.
2020-12-04 18:27:49 +01:00
Javi Martín
82b0a6a92d Remove new CSV report generation
The new CSV report was more configurable and could work on proposals,
processes and comments. However, it had several issues.

In the public area, by default it generated a blank file.

In the admin section, the report was hard to configure and it generated
a file with less quality than the old system.

So until we improve this system, we're bringing back the old investment
CSV exporter.

This commit reverts most of commit 9d1ca3bf.
2019-11-06 00:04:02 +01:00
Javi Martín
88c70366a7 Apply rubocop rules for trailing commas 2019-10-26 20:10:33 +02:00
Javi Martín
8e3bfa0d72 Apply Style/RedundantReturn rubocop rule
We were already following this pattern most of the time.
2019-10-26 13:26:35 +02:00
Javi Martín
42d2e5b3ad Apply Rails/InverseOf rubocop rule
Not doing so has a few gotchas when working with relations, particularly
with records which are not stored in the database.

I'm excluding the related content file because it's got a very peculiar
relationship with itself: the `has_one :opposite_related_content` has no
inverse; the relation itself is its inverse. It's a false positive since
the inverse condition is true:

```
content.opposite_related_content.opposite_related_content.object_id ==
  content.object_id
```
2019-10-25 19:29:12 +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
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
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Senén Rodero Rodríguez
ed750f6cce Move private method to a more reusable location
This method will be used by any translatable model that uses pg_search
feature so it's better to have it within globalizable model concern so
all translatable models can use it.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
036a3d7636 Add translations to debate pg_search_scope
Some Debate attributes are now translatable so we need to include all
existing translations on pg_search scope.
2019-06-27 09:19:36 +02:00
Senén Rodero Rodríguez
740c738fc5 Add debate translations 2019-06-27 09:19:36 +02:00
German Galia
9d1ca3bfd4 Report generation. Download csv 2019-06-12 10:17:31 +02:00
Juanjo Bazán
b7d9ef6377 models inherits from 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
Javi Martín
6682121069 Reuse code to set and order by a random seed 2019-02-20 12:10:12 +01:00
decabeza
4e4804e180 Replace total votes to cached_votes_score on debates
This show votes_score as result of votes_up minus votes_down
2019-02-12 18:42:35 +01:00
Julian Herrero
ef835bef1c new algorithm for filter 'most active' 2018-12-13 11:42:22 +01:00
Angel Perez
a143fa447b Ensure recommendations are only shown when enabled 2018-07-15 21:28:58 -04:00
Angel Perez
522c206f6d Enable 'Recommended debates' setting for users 2018-07-15 21:28:57 -04:00
María Checa
a1f840e8fd Added improvements to related contents 2018-01-12 18:35:15 +01:00
rgarcia
2b52d26d82 refactors notifications into concerns and shared examples 2017-12-14 16:15:30 +01:00
Bertocq
13f5fa55ab Use Relationable concern on Debates, Proposals and Budget Investments 2017-11-29 19:01:12 +01:00
Bertocq
ce0a7f6fad Rubocop autocorrections 2017-10-17 22:00:00 +02:00
Senén Rodero Rodríguez
92c774cdeb Merge with master 2017-09-28 13:36:20 +02:00
Bertocq
c5059f7292 Fix Style/ParenthesesAroundCondition rubocop issues 2017-09-25 22:46:09 +02:00
taitus
edbbe6174b Refactor specs because now recommendations only return results asociated to user interests 2017-08-03 00:23:06 +02:00
taitus
b412f8a88c Avoid duplicate proposals with group on query. Avoid show successful proposals on recommendations. 2017-08-02 14:31:02 +02:00
taitus
7afacf3a2f Force distinct to recommendations methods. Sort by recommendations on home carousel. 2017-08-02 12:52:55 +02:00
taitus
52e3610876 Minimum required by consul core. Remove comments. Fix texts. Decrease size of methods. 2017-08-02 00:15:03 +02:00
taitus
5f1bdb2f94 Rename recommendeds to recommendations 2017-08-01 16:31:45 +02:00
taitus
dc5584086a Styles for filters. Refactor commentable action. 2017-08-01 16:31:45 +02:00
taitus
fe3bb7a389 Add recommended tab on proposals and debates index. 2017-08-01 16:31:44 +02:00
Bertocq
2888c20489 Fix all Style/RedundantSelf rubocop issues 2017-07-05 11:55:52 +02:00
Alberto Miedes Garcés
9ec8b166d7 Use scopes for better query performance 2017-06-01 20:04:51 +02:00
Alberto Miedes Garcés
6b47ce065f Fix buggy associations 2017-01-27 14:27:28 +01:00
Alberto Miedes Garcés
5b7cbccd19 Merge branch 'master' into api-dev 2017-01-26 12:39:59 +01:00