Commit Graph

14280 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
Javier Martín
3ecab8af13 Merge pull request #3725 from consul/attributes_in_specs
Check page content from the user's perspective
2019-09-30 15:07:44 +02:00
Javier Martín
59e3e3232d Merge pull request #3732 from consul/voters_in_specs
Simplify creating  associations in specs
2019-09-30 14:38:05 +02:00
Javi Martín
1ebfa04578 Check texts from the user's point of view
This way we also simplify the code by avoiding instance variables.
2019-09-30 14:29:15 +02:00
Javi Martín
2a95676935 Check content instead of current path
This way we check the page from the user's point of view.
2019-09-30 14:29:15 +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
0f80dabfe4 Compare against literal title in feature specs
We were creating records with a title we manually set, so to be
consistent with the rest of the code, in the test we check the title is
present using a string literal.

This way we can also remove useless assignments while keeping the code
vertically aligned.
2019-09-30 14:29:15 +02:00
Javi Martín
0fe0d8e57c Use title in specs add_to_ballot method 2019-09-30 14:29:15 +02:00
Javi Martín
ef24962f40 Simplify variable usage in features specs
We usually check against the literal text instead of storing the text in
a variable.
2019-09-30 14:29:15 +02:00
Javi Martín
92bfc9ed17 Use text instead of IDs in feature specs
This way we write the tests from the user's point of view: users can see
(for example) a proposal with the title "Make everything awesome", but
they don't see a proposal with a certain ID.

There are probably dozens, if not hundreds, of places where we could
write tests this way. However, it's very hard to filter which ones are
safe to edit, since not many of them have an HTML class we can use in
the tests, and adding a class might generate conflicts with CSS styles.

So, for now, I'm only changing the ones allowing us to cleanly remove
useless assignements while maintaining the code vertically aligned.
2019-09-30 14:29:15 +02:00
Javi Martín
d856bb4ab7 Use ID literal for comparisons in grapql tests
While this is potentially very dangerous because assigning the ID does
not increase the ID sequence, it's safe to do so in tests where we
assign the ID to every record created on a certain table.

Even so, I'd consider it a bad practice which must be used with care. In
this case I'm using it because we look for IDs in the response, and
most tests in this file use literals to compare the response.

This changes makes it possible to remove unused variables while keeping
the test readable.
2019-09-30 14:29:15 +02:00
Javi Martín
3af958bc92 Simplify checking attributes in GraphQL specs
Since we're obtaining titles and usernames in the response, it's easier
to compare them to titles and usernames we manually set.

Furthermore, this way we avoid many useless assignments.
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
c34ebc9a53 Simplify creating images with title for milestones 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
c15b58f927 Use traits instead of methods to create headings 2019-09-30 14:10:46 +02:00
Javi Martín
1973c61552 Simplify creating notifications in specs 2019-09-30 14:10:46 +02:00
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