Commit Graph

235 Commits

Author SHA1 Message Date
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
94d2496f8f Add missing has_many relations for users
Usually when we specify a `belongs_to` relations, we also specify its
equivalent `has_many`. That allows us to write, for example:
`topic.user.topics`.
2019-10-25 19:27:30 +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
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
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
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
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
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
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
lalo
7c9c50f4c6 Add Model changes to work with votation_types 2019-06-12 19:32:41 +02:00
German Galia
74083df10f Add historic fields to participatory budget 2019-06-12 18:03:53 +02:00
German Galia
9ce524e1f3 Create tracker rol 2019-06-12 16:23:40 +02:00
German Galia
16ffa2a259 Add change log in investment participatory budget 2019-06-12 13:06:20 +02:00
lalo
46e5d6a9fa Create Legislation::PeopleProposal model 2019-06-06 17:22:49 +02:00
Javi Martín
dadbf873ba Order translations using ruby
Joining the translations table caused duplicate records to appear.
Ordering with SQL is simply too hard because we need to consider
fallback locales.

Thanks Senén for providing most of the tests in the poll spec.
2019-06-03 18:35:59 +02:00
voodoorai2000
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
Javi Martín
202fb44008 Add poll stats by age and channel 2019-05-21 13:50:17 +02:00
Javi Martín
7b408a4b88 Add poll stats by gender and channel 2019-05-21 13:50:17 +02:00
Julian Herrero
6e88031537 Fix several rubocop warnings
Metrics/LineLength: Line is too long.
RSpec/InstanceVariable: Use let instead of an instance variable.
Layout/TrailingBlankLines: Final newline missing.
Style/StringLiterals: Prefer double-quoted strings.
2019-04-17 17:40:56 +02:00
Juanjo Bazán
b7d9ef6377 models inherits from ApplicationRecord 2019-04-17 17:40:56 +02:00
taitus
638c80760f Fix queries and scopes after column deletion
Some queries were accessing original column instead of the new translatable one. This should have been causing unexpected behavior for requests maded in a different locale than the application default.
2019-04-17 17:40:56 +02:00
rgarcia
c979cc7411 Fix uniq deprecation warning
DEPRECATION WARNING: uniq is deprecated and will be removed from Rails
5.1 (use distinct instead) (called from block in <class:User> at
/home/travis/build/consul/consul/app/models/user.rb:67)
2019-04-16 17:28:07 +02:00
alejandro
84338592da removes devise-async for delayed devise emails
Custom overwrite of the devise implementation following
https://github.com/plataformatec/devise#activejob-integration
2019-04-16 17:28:07 +02:00
Javi Martín
4c35df4812 Use double quotes inside string interpolation 2019-03-25 14:58:54 +01:00
Julian Herrero
3ba961a2d7 Use double quotes in models 2019-03-14 17:25:43 +01:00
decabeza
73a0f999ad Add order to voted headings names 2019-02-12 17:19:36 +01:00
voodoorai2000
f4b8099703 Simplify sql query 2019-02-12 17:18:38 +01:00
Marko Lovic
264c4e747b Improve User#headings_supported_within_group performance
Performs a single DB call instead of 3
2019-02-12 17:16:49 +01:00
Marko Lovic
e47cbe2a10 Extract "supported headings" logic to User method
In preparation to use this method from views where
it doesn't make sense for it to be associated with
a specific investment.
2019-02-12 17:16:29 +01:00
Javier Martín
3b82057178 Fix admin menu not showing for some admins
There was a bug when finding the manager login, since we were only using
the last digit of their user ID.
2018-07-28 22:06:11 +02:00
Javier Martín
157cd001d5 Add spec to expose a bug finding manager logged in
I've moved the method to the User model in order to make it easier to
test. I'm not sure where it belongs, though.

There was already a failing spec in `spec/features/management_spec.rb`,
but it passed if run standalone because it only failed if previous tests
had already created nine users or more.
2018-07-28 22:03:33 +02:00
Angel Perez
7bb1da1804 Adapt backend to enable flagging/unflagging investments 2018-07-20 18:42:33 -04:00
rgarcia
f670019325 Deal gracefully with recommendations of hidden proposals
We were seeing an exceptions in the home page when displaying
recommendations. This was due to trying to load tags of hidden proposals

With this commit we are skipping proposals that that have been hidden,
which will hopefully solve this exception
2018-07-10 17:47:28 +02:00
iagirre
21b1d00205 Add backend for the moderators
Add new routes for the proposal notifications edition and
abilities to let moderators edit it (mark as ignored, hide, etc.).

The notifications are not flaggable because they doesn't work like that,
but in a similar way. The moderator/administrator is in charge of hidding
them through the UI, so the normal users don't flag it as inappropriate.

New controller Moderation::ProposalNotification to manage the moderators
work.
2018-07-02 18:17:45 +02:00
Raúl Fuentes
376ce443ef Add logic to user verification
changed functions on verification.rb, the first thing they do is
return true whene skip_user_verification is active.
changed show_welcome_screen? on user.rb, now its shows the welcome
page even with te option active.
changed welcome.html.erb, now if the user see this view and the
option is activated, all 4 checks are green, not only 2.
2018-05-22 15:02:35 +02:00
Bertocq
65288573b5 Fix user administrators scope relation 2018-02-22 00:42:40 +01:00
Bertocq
1434449b84 Fix line length issues at User model 2018-02-19 11:09:19 +01:00
Bertocq
9925e2b02f Extract inline query to User scope & refactor 2018-02-19 11:09:19 +01:00
Bertocq
cd66ba5d54 Rubocop autocorrections 2017-11-13 02:22:00 +01:00
María Checa
841ef2a3a2 Merge branch 'master' into 1856-legislation_processes_proposals_phase 2017-10-09 17:19:07 +02:00
María Checa
ac5620c583 Merge branch 'master' into 1856-legislation_processes_proposals_phase 2017-09-21 21:24:56 +02:00
María Checa
ba041f90c8 Removed unnecessary parts in Legislation Proposals 2017-09-21 16:17:11 +02:00
BertoCQ
f67ba62c49 Merge branch 'master' into user-recomendations 2017-09-19 18:56:12 +02:00
María Checa
c1672bdbf4 Legislation proposals adaptation in some models and initializers 2017-09-19 10:10:10 +02:00
Bertocq
e4e78c8f16 Rubocop autocorrections 2017-09-14 15:08:35 +02:00
Raimond Garcia
2519f232ab Merge branch 'master' into user-recomendations 2017-09-05 17:15:42 +02:00
taitus
90518d4f99 Refactor participants. Add scopes on User. 2017-09-05 12:54:32 +02:00
taitus
0d76004636 Simplify and refactor method to calculate community participants 2017-09-05 12:54:32 +02:00
taitus
4539c5fa00 Refactor and tests. 2017-09-05 12:52:14 +02:00
taitus
08f58b845d Add participants to community 2017-09-05 12:51:08 +02:00