Commit Graph

14280 Commits

Author SHA1 Message Date
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
Javi Martín
4e72d9f3b7 Remove useless assignments to return values 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
Javier Martín
d059a564f2 Merge pull request #3722 from consul/use_traits
Use traits to simplify specs
2019-09-25 12:29:33 +02:00
Javier Martín
08730ba7f1 Merge pull request #3721 from consul/simplify_testing_array
Simplify testing array contents
2019-09-25 11:58:17 +02:00
Javier Martín
0bb6f8029e Merge pull request #3720 from consul/featured_proposals_specs
Update featured proposals specs
2019-09-25 11:55:24 +02:00
Javier Martín
4ee494a46d Merge pull request #3719 from consul/remove_redundant_code
Remove redundant code
2019-09-25 11:53:36 +02:00
Javier Martín
8d41114066 Merge pull request #3718 from consul/remove_obsolete_code
Remove unused and obsolete code
2019-09-25 11:46:09 +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
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
8ec8002acd Enable featured proposals when they're used
These specs were added before we disabled featured proposals by default.
After that, they were passing, but they were not testing the scenario
they were supposed to test.
2019-09-24 20:05:02 +02:00
Javi Martín
52c8691aae Don't create featured proposals if disabled
Before we disabled featured proposals by default, there were many tests
creating them because they were needed in order to create non-featured
proposals.

But now these tests don't need to create featured proposals anymore.
2019-09-24 20:04:39 +02:00
Javi Martín
2ad6ced12f Create featured proposals if enabled
We had a case where we created 5 extra records in pagination and checked
2 records were present, because the other 3 were automatically
considered featured proposals.

Explicitely creating featured proposals let us create 2 extra records
 and check 2 records are present, which is far more intuitive.
2019-09-24 20:03:52 +02:00
Javi Martín
01862d6664 Remove unused attributes creating a heading
The "name" attribute is automatically generated by the budget heading
factory. And the "price" attribute is out of context and not needed
since this test doesn't create investments.
2019-09-24 20:02:09 +02:00
Javi Martín
f5849cb5d8 Remove unnecessary question creating answers
Questions are automatically created by the poll_question_answer factory.
2019-09-24 19:55:42 +02:00
Javi Martín
e1c09769a8 Remove unnecessary data in polls spec
This data was added in commit 62088bc6, but the changes in that commit
don't seem to be related to the number of questions in a poll.
2019-09-24 19:55:37 +02:00
Javi Martín
ef0330f671 Remove duplicate test
One test was testing regular users can't access results, and another one
was testing neither regular users nor managers can. So the second test
can just test the admin scenario, and we're still covering everything.
2019-09-24 19:50:18 +02:00