Commit Graph

25 Commits

Author SHA1 Message Date
Javi Martín
24ccf23ed8 Don't save the answer if the voter is not recorded
Up until now, we were assuming the voter was valid, but were not raising
an exception if it wasn't. And in the user interface everything seemed
to be working properly.

We were having this issue when skipping verification, when there could
be voters without a document number, which would be considered invalid.

Raising an exception when failing to save the voter and making sure the
answer and the voter are saved inside a transaction solves the problem.
2020-08-07 11:52:24 +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
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
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
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
d42b9ff4a5 Extract method to get valid answers to a question
This way we remove duplication and we avoid a multi-line block in a
validation rule, which made the code hard to read.
2019-10-05 14:34:52 +02:00
Juanjo Bazán
7ab602175a makes models inherit 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
Julian Herrero
673ec075eb Make answers translatable 2018-09-20 17:13:40 +02:00
Bertocq
08823153a9 Correct answer inclusion validation for no question scenario 2017-10-18 02:03:58 +02:00
Bertocq
8d2945e8a2 Fix answer attribute validation to check question's question_answers inclusion 2017-10-18 01:31:34 +02:00
Bertocq
9a396fe634 Fix record_voter_participation and usage on specs 2017-10-07 10:48:24 +02:00
María Checa
bcfd1a844a Poll voter token 2017-10-06 20:44:47 +02:00
Bertocq
165509b525 Switch from Poll::Answer to Poll::Voter usage and small fixes 2017-10-06 18:59:47 +02:00
María Checa
35148015b9 Added token to poll voters 2017-10-06 18:43:00 +02:00
Bertocq
1806bd3df4 Add token string attribute to Poll Answer 2017-10-06 14:28:57 +02:00
rgarcia
4aaf681d2d uses new answer model in user facing interface 2017-10-04 17:45:51 +02:00
rgarcia
085991c624 allows voting only in one origin: booth or web 2017-10-02 16:22:31 +02:00
rgarcia
60fb142fff adds comprehensive validation specs 2017-10-02 13:39:55 +02:00
rgarcia
b623422805 allows users to change their vote without refreshing the page 2017-10-02 13:14:58 +02:00
Bertocq
02524b164a Rubocop autocorrections (indentations, revers unless to if, extra spaces) 2017-06-08 12:14:35 +02:00
rgarcia
6c34599e1e adds officer residence check and user voting 2017-01-29 00:36:20 +01:00
Juanjo Bazán
51be80eedc removes answer <-> voter association 2017-01-27 11:59:37 +01:00
Juanjo Bazán
b13a76963a records participation of user via web
answering a poll question creates a voter with the user data to record
participation in question’s poll
2017-01-25 14:21:03 +01:00
Juanjo Bazán
6bc4f5b307 adds Poll::Answer model for web users
PartialResults is kept for booth results
2017-01-25 12:46:44 +01:00