Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
f535d81877 Simplify creating videos for a poll in specs 2019-09-30 14:10:46 +02:00
Javi Martín
11723fbb72 Simplify creating a topic with a community 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
c6acc70570 Simplify assigning a name to an officer 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
Javier Martín
3b5cbc2150 Merge pull request #3731 from consul/array_specs
Test exact array contents where possible
2019-09-30 00:35:54 +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
f69a0336a5 Use eq to match arrays with 1 element
It's shorter, and easy to read.
2019-09-29 23:24:53 +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
Javier Martín
24f14ea772 Merge pull request #3730 from consul/remove_obsolete_code
Remove obsolete code
2019-09-29 23:24:22 +02:00
Javi Martín
f426b25fe5 Remove unneeded factories
These factories were only used in one place and they even declared ID
attributes. Using the comment factory with the `commentable` attribute
does the same thing.
2019-09-29 22:52:53 +02:00
Javi Martín
9787f7f125 Remove nonexistent instance variable
The instance variable was being evaluated to `nil`, and the budget was
automatically created by the `set_denormalized_ids` method in the budget
investment class.
2019-09-29 22:52:53 +02:00
Javi Martín
eac7427755 Remove line auto-assigning a variable to nil
This is one of the most strange behaviours in ruby: if a variable
doesn't exist, assigning to itself will return `nil`.

So a line like:

mdmkdfm = ooops if mdmkdfm.respond_to?(:uiqpior)

Surprisingly will not raise any errors: the nonexistent `mdmkdfm`
variable will be evaluated to `nil`, `mdmkdfm.respond_to?(:uiqpior)`
will evaluate to `nil.respond_to?(:uiqpior)`, which will return `false`,
and then the line will be evaluated as `mdmkdfm = ooops if false`, which
will return `nil`.

Maybe in the future Ruby will change this behaviour. We hope CONSUL is
now in better shape if that ever happens :).
2019-09-29 22:52:53 +02:00
Javi Martín
eecc027fd3 Remove useless notification in emails spec
The `create_proposal_notification` method won't create a new
notification when a proposal has no supporters, so in the test
`notification3` was actually the same as `notification2`, related to
`proposal2`.
2019-09-29 22:52: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
92acd0f2b1 Remove redundant publication date attribute
The attribute made sense before we changed it in commit ba1a6b4c. Since
then, all milestones have the same date, so the attribute doesn't affect
the test at all.
2019-09-29 22:31:14 +02:00
Javi Martín
49b47dd5f4 Remove useless valuation comment creation
The valuation comment doesn't show up in the comment show action because
it's not a child of the parent comment. With a regular comment, the test
passes as well.

However, if we make the valuation comment a child of the parent comment,
it shows up both in the index and show actions. That's because the
method `root_descendants` in the `CommentTree` class doesn't filter
valuation comments. I'm not sure whether it's a bug or the intended
behaviour.
2019-09-29 22:31:14 +02:00
Javi Martín
ce2b81f790 Fix typo in communities spec
We were using the same order for most commented and for newest, so the
test wasn't as effective as it could be.
2019-09-29 22:31:14 +02:00
Javi Martín
1cfc6c121d Remove unnecessary attributes in communities spec 2019-09-29 22:31:13 +02:00
Javi Martín
db90672fdd Fix notifiable in-app topic specs
These specs had never been tested before and were always broken.
2019-09-29 22:31:13 +02:00
Javi Martín
dcc9a6b561 Use symbols instead of constants for behaviours
This way we can be more flexible about the factory we can pass as
parameter.
2019-09-29 22:31:13 +02:00
Javi Martín
b8d3f426a5 Fix wrong file name for test file
The file name finished with `_specs.rb` instead of `_spec.rb`, and so it
wasn't being tested at all.
2019-09-29 22:31:13 +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
087b4bf2a6 Remove unused variables 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
Javier Martín
1ba610071f Merge pull request #3729 from consul/fix_extra_records
Fix extra records in investments and polls
2019-09-29 22:25:33 +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
Javier Martín
edc396a8e2 Merge pull request #3726 from consul/test_calculate_winner
Add more tests to calculate winners
2019-09-25 16:05:38 +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
Javier Martín
5463753553 Merge pull request #3724 from consul/isolated_unused_variables
Remove isolated useless assignments
2019-09-25 14:54:03 +02:00
Javier Martín
6ae764c414 Merge pull request #3723 from consul/simplify_poll_factories
Simplify data creation in poll factories
2019-09-25 14:42:19 +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
5cbd160f11 Move login_as after creating data for a test
It doesn't really affect the tests, but it helps isolate useless
assignments, and we already did it this way 94% of the time.
2019-09-25 12:43:44 +02:00
Javi Martín
24aa4744f1 Simplify login for officer user in tests
The same way it's done in other places. We also remove a useless
assignment.
2019-09-25 12:43:44 +02:00
Javi Martín
175163adb6 Use named parameter in mappable shared example
Boolean arguments are harder to read, so we added a useless variable.
This is the perfect scenario for a named parameter.
2019-09-25 12:43:44 +02:00