Commit Graph

1129 Commits

Author SHA1 Message Date
Javi Martín
a9159e0ec8 Directly assign valuators in specs
Creating a record and then assigning an association makes the code even
harder to follow.
2019-09-30 15:08:27 +02:00
Javi Martín
bbf8eebb80 Check lines count instead of IDs in results spec
This is easier to follow
2019-09-30 14:29:15 +02:00
Javi Martín
bd795be80e Check for attribute values in current budget tests
Assigning a variable to each budget we declare results in useless
assignments. We could just delete the three useless assignments and
leave the fourth one, but I find the code easier to read if we use the
name of the budgets to differenciate between them. This way we also keep
the code vertically aligned.
2019-09-30 14:29:15 +02:00
Javi Martín
e2b536e8f8 Simplify adding investments to ballots in specs 2019-09-30 14:10:46 +02:00
Javi Martín
19edf0466b Simplify assigning booth to a voter
Unless we're using the booth assignment for something else in the test,
when creating a voter from booth, specifying the poll and the booth is
enough to create a booth assignment.
2019-09-30 14:10:46 +02:00
Javi Martín
bd73c5f263 Use final trait for poll officer assignments
We were only using it in a few places.

I've left the current `final: true` statement in a few places where
using a trait would break vertical alignment, just in case.
2019-09-30 14:10:46 +02:00
Javi Martín
b431273869 Simplify creating officer assignments in specs
Note we usually cannot make it simple because officer assignments are
usually assigned to both a poll and a booth, and on a certain date.
However, in the few cases where the booth nor the date don't matter, we
can make the code a bit easier to read.
2019-09-30 14:10:45 +02:00
Javi Martín
71c24f844d Simplify creating ballot lines in specs 2019-09-30 14:10:44 +02:00
Javi Martín
5ff1162038 Simplify creating follows in specs
While in theory we wouldn't need to use the `transient` nor the
`after(:create)` because there's already a `has_many :through`
association with followers, Factory Bot / ActiveRecord don't
automatically associate the followable, resulting in an invalid record
exception.
2019-09-30 13:34:31 +02:00
Javi Martín
818b442d52 Simplify creating voters in specs 2019-09-30 00:36:40 +02:00
Javi Martín
994b5c99c2 Simplify taggings creation in specs 2019-09-30 00:36:40 +02:00
Javi Martín
c2d7420107 Simplify testing records exclusion
When we already have tests checking which records are included, in the
tests testing records are not included we can just generate records
which will not be included and test against an empty array.

We were already using this approach in some tests. This way we also
avoid useless assignments.
2019-09-29 23:57:35 +02:00
Javi Martín
35143ac43e Use be_empty instead of not_to include
Using `not_to include` does not test for other elements which could be
present in the array.
2019-09-29 23:57:35 +02:00
Javi Martín
fd1325768f Check exact array contents instead of inclusion
We're using `eq` and `match_array` in most places, but there were a few
places where we were still checking each element is included in the
array. This is a bit dangerous, because the array could have duplicate
elements, and we wouldn't detect them with `include`.
2019-09-29 23:57:35 +02:00
Javi Martín
9f0088396e Only create records on tests using them
The test or the draft phase legislation filter was using an entirely
different set of records, but was still creating the records used in the
open and past filter as well.

This made it hard to test the filter, since it returned records from
both sets.

Grouping the past and open filters together guarantees their records
won't be created in the phase draft test, and so we can test the exact
contents of the array.
2019-09-29 23:57:35 +02:00
Javi Martín
44ffcfba2c Simplify test for heading names
We were using `to_sentence` to check the order, while it's easier to
just check the exact contents of the array.

Furthermore, using `to_sentence` checked the order of the array, so it
was a potentially flaky spec since the method doesn't specify an order
and PostgreSQL doesn't guarantee the order of the records.
2019-09-29 23:54:11 +02:00
Javi Martín
a04a289850 Simplify testing arrays exact contents
Instead of testing the contents of each element, we can test the whole
array at once.
2019-09-29 23:24:53 +02:00
Javi Martín
9ad5d82e9d Fix typos to make tests more robust
Apparently we forgot to use the variables which meant the tests weren't
testing exactly what they were supposed to test.
2019-09-29 22:31:14 +02:00
Javi Martín
0719b834c9 Remove unnecessary attributes in investment specs
The group is automatically assigned when we assign the heading. The
budget isn't needed either, except for a special case related to the
reason to be rejected.
2019-09-29 22:31:13 +02:00
Javi Martín
7ee9c0d042 Remove obsolete method to get voted headings
This method isn't used since commit e47cbe2a, where we replaced it with
`headings_voted_within_group`.
2019-09-29 22:31:13 +02:00
Javi Martín
bfd39a13e0 Remove unnecessary attributes in proposals spec
These tests are only checking which proposals are not included in the
recommendations, so we don't need to sort the included ones, just like
we don't use the cached votes up attribute in the tests preceeding these
ones.
2019-09-29 22:31:13 +02:00
Javi Martín
97375f557f Fix typo in proposals spec
The test passed even if proposal recommendations returned archived
proposals, because we forgot to add the tag list the user is interested
in.
2019-09-29 22:31:07 +02:00
Javi Martín
028f1e3fc4 Fix typo in direct message spec
Now the test makes more sense, since it checks the third message for the
same sender is valid.
2019-09-29 22:31:07 +02:00
Javi Martín
3b11f8b567 Avoid duplicate records in current_or_recounting
Joining two scopes with `+` does not remove duplicate records. Luckily
now that we've upgraded to Rails 5, we can join scopes using `.or`.

The test was testing for the presence of elements, bud didn't test for
duplicate records. Testing the exact contents of the array revealed this
behaviour.
2019-09-26 19:58:02 +02:00
Javi Martín
45c6a70d91 Fix extra nil added to assigned investment IDs
When `valuator_group` was `nil`, `[valuator_group&.investment_ids]` is
evaluated to `nil`, and so we were adding an extra element to the array.

We could add a `compact` call to the resulting array, but I find it
easier to convert `nil` to an array using `to_a`.
2019-09-26 19:58:02 +02:00
Javi Martín
1bb53b11fb Add a test for an edge case calculating winners
We weren't testing what happens if the next investment exceeds the
budget, but the following one doesn't.
2019-09-25 15:24:59 +02:00
Javi Martín
5a934de5a6 Add test for lines order calculating winners
We were creating the investments with more ballot counts first in every
test, so the tests would pass if we ordered the investments by creation
date instead of ordering them by the number of ballot lines.
2019-09-25 15:19:55 +02:00
Javi Martín
5fa155ceda Simplify tests checking for invalid email
We also remove useless assignments, and use a neutral email address in
the sample data.
2019-09-25 12:43:44 +02:00
Javi Martín
ee0031ccb3 Remove isolated data creation useless assignments
While there are other variables in these tests, they're not part of the
setup of the test, and so these ones can be removed while keeping the
code easy to read.
2019-09-25 12:43:44 +02:00
Javi Martín
7b0771106e Remove isolated useless assignments
These variables are not surrounded by other assignments, and so they can
safely be removed without making it harder to read the code vertically.
2019-09-25 12:43:44 +02:00
Javi Martín
cfaa6d6567 Remove useless assignment in i18n content spec 2019-09-25 12:43:44 +02:00
Javi Martín
320b7550ed Simplify assigning poll to a booth in specs
We were creating booth assignments explicitely, but we can use the
`has_many :through` relationship to make the code easier to read.
2019-09-25 12:38:37 +02:00
Javi Martín
12cdbf6196 Simplify assigning officer to a poll in specs
While it could be argued we're hiding the real way we've defined
associations in our models, the tests are so much easier to read when we
don't have so many lines just creating data.

Furthermore, developers who care about vertically aligning the code will
be glad to see some variables disrupting this alignment are now gone.
2019-09-25 12:38:37 +02:00
Javi Martín
49f81c9488 Add trait to create users with proposal and debate 2019-09-24 21:34:06 +02:00
Javi Martín
24e8f07dae Add unfinished trait to investment factories
Now the code is symmetrical since we also use `finished`.
2019-09-24 21:34:06 +02:00
Javi Martín
52e54363ae Add trait to create a poll associated to a budget 2019-09-24 21:34:06 +02:00
Javi Martín
19a41eb651 Rename trait with_answers to yes_no
We barely use this trait. In the votation type spec we're probably using
it wrong, and in the answer spec we assume one of the answers is going
to be "Yes".

The name `yes_no` is more expressive, since it makes it clear what the
answers are.
2019-09-24 21:34:06 +02:00
Javi Martín
aeb1655961 Use budget phase traits
We were already using them in many places, but not everywhere.
2019-09-24 21:34:06 +02:00
Javi Martín
cced12c3a0 Use feasibility traits to simplify code 2019-09-24 21:34:06 +02:00
Javi Martín
eb53e033be Use finished trait to simplify code
It's more concise than writing `valuation_finished: true`.
2019-09-24 21:34:06 +02:00
Javi Martín
30a30c5f00 Use with_administrator trait to simplify code
It's more concise than writing `administrator: create(:administrator)`
2019-09-24 21:34:06 +02:00
Javi Martín
2b2c528098 Use hidden trait in specs
We were using it in most places, but there were a few where we still
used `hidden_at: Time.current`.
2019-09-24 21:34:06 +02:00
Javi Martín
f27beb1e47 Simplify testing array contents
We were testing for the size and the content of the elements when we
could test for the array itself.
2019-09-24 21:32:52 +02:00
Javi Martín
4301937e85 Check arrays are empty instead of size 0
In ruby we check for `array.empty?` instead of `array.size == 0`, so
it's natural to write the tests in the same way.
2019-09-24 21:32:28 +02:00
Javi Martín
98fe8349d7 Use match_array instead of sorting arrays
It does the same thing, and it's easier to read.
2019-09-24 20:50:49 +02:00
Javi Martín
4a80653d2f Remove redundant checks for array size
If we check the exact contents of the array, checking the size is
implicit.
2019-09-24 20:50:48 +02:00
Javi Martín
fe5b45ed18 Remove unnecessary poll creating assignments
The factory creating assignments automatically assigns a poll to it, so
we don't use the poll for anything else, there's no need to explicitely
create it.
2019-09-24 19:48:22 +02:00
Javi Martín
9d627f2db9 Remove redundant I18nContent scope
Since two records cannot have the same key, having a scope that will
always return just one record is the same as using `find_by_key`.
2019-09-24 19:29:46 +02:00
Javi Martín
cb2069858c Remove unnecessary code
It looks like these variables were left by accident. The Ruby
interpreter was giving us warnings about unused variables.
2019-09-24 18:49:40 +02:00
Javi Martín
66334b5757 Add globalizable tests for all translatable models
So now we test in depth at the model level, and can be a bit more
relaxed about integration tests for translations.

Note we're defining some extra factories to make sure all translatable
attributes with presence validation rules are mandatory. This way we can
simplify the way we obtain required fields, using `required_attribute?`.
Otherwise, fields having an `unless` condition in their presence
validation rules would count as mandatory even when they're not.
2019-09-23 18:01:44 +02:00