Commit Graph

2813 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
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
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
c34ebc9a53 Simplify creating images with title for milestones 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
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
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
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
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
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
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
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
53fa527118 Add invisible_to_valuators trait to investments
Now the code is symmetrical since we also use `visible_to_valuators`.
2019-09-24 21:34:06 +02:00
Javi Martín
086e960d09 Add trait to simplify image creation in specs 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
4edab79910 Use yes_no trait to simplify creating answers
We lose some variety in our answers, though, but on the plus side, we
reduce the risk of trademark issues :P.
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