Commit Graph

952 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
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
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
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
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
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
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
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
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
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
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
fcaa30dc57 Remove obsolete URL reference
This URL was accidentally copied from Madrid's repository. However, we
don't use it in CONSUL.
2019-09-24 18:49:40 +02:00
Javi Martín
fb6d12c8ab Remove obsolete data creation
This data is obsolete since commit 9d1ca3bf.

Note we should have probably moved the test to the model, since now the
`to_csv` method isn't tested anywhwere, and we should probably add a
test in the future. The code now uses the new DownloadSetting model,
though, making it hard to test.
2019-09-24 18:49:40 +02:00
Javi Martín
748ee3d804 Remove obsolete confirm messages references
This code is obsolete since commits 122b1703 and bbf3faa7.
2019-09-24 18:33:47 +02:00
Javi Martín
44d137a4c0 Simplify translatable tests in admin section
These feature tests were taking too long, we can't run them for every
single model.

I'm taking the approach of using one different model for each test, but
in theory only using a few models covering every possible scenario
would be enough.
2019-09-23 18:01:44 +02:00
Javi Martín
ef7606bb45 Move translatable file to features folder
This change breaks the tests, but makes future commits easier to review.
2019-09-23 18:01:44 +02:00
Javi Martín
41c99d9b27 Let Globalize use I18n locale
This is a mistake I made in commit f2ef27d3. Back then I thought we
needed to keep Globalize.locale and I18n.locale in sync, but the truth
is it automatically happens when setting Globalize.locale to nil.

So now we can use I18n.with_locale (at least in the tests) and forget
about Globalize, which will make it easier to switch to Mobility in the
future.
2019-09-23 18:01:44 +02:00
Javi Martín
c8c8a7bc30 Simplify investment creation in specs
Now factories define default headings for investments, so there's no
need to create a group and a heading to create an investment.

Likewise, in order to create a heading it isn't necessary to specify a
group anymore; specifying the budget is enough.

It's possible that there are more similar cases we haven't simplified
yet; I'm only addressing the obvious ones.
2019-09-23 16:51:30 +02:00
Javi Martín
da121ebc53 Remove redundant setting resets in after blocks
Settings are stored in the database, and so any changes to the settings
done during the tests are automatically rolled back between one test and
the next one.

There were also a few places where we weren't using an `after` block but
changing the setting at the end of the test.
2019-09-23 13:47:45 +02:00
DenisNikolski
5627c8ccf4 add test for booths search 2019-09-21 16:25:20 +03:00
DenisNikolski
54c4a8d34b fix shifts_spec 2019-09-13 22:51:07 +03:00
Javier Martín
f5a6df4316 Merge pull request #3692 from consul/admin-booth-assignments
Hide polls created by users on admin poll booth assigments
2019-09-12 12:54:42 +02:00
Javi Martín
cf5b538c1c Check page between AJAX requests
While the test should work without this assertion, the intention of the
test is to check what happens if a user selects and investment and, once
it's selected, clicks the "next" link.
2019-09-11 19:38:35 +02:00
Javi Martín
9d6ed7a085 Show only defined columns on inserted rows
When we were inserting a row or replacing an existing one (just like we
do when we click the link to select an investment), we were entering a
row containing all columns, and all of them were displayed even if they
had been excluded using the column selector.

This caused the table to move in a strange way, which sometimes made the
investment selection tests fail.
2019-09-11 19:38:34 +02:00
decabeza
08e820c134 Hide polls created by users on admin poll booth assigments 2019-09-11 18:44:32 +02:00
Javi Martín
5ad41d9ac7 Add a break to avoid case fallthrough
In JavaScript, when there isn't a `break` or `return` statement inside a
`switch` case, the next case will be executed as well.

That wasn't a problem here because CoffeeScript automatically inserts a
`return` statement in this specific situation. However, since we don't
want to return the result of the `hide()` operation, it might be easy to
accidentally remove the `return` statement, causing the code to break.

I've added a test for the scenario where neither `break` nor `return`
statements are present, so we don't run into this error.
2019-09-11 02:05:04 +02:00
Javi Martín
c05b9c2aac Apply Capybara/CurrentPathExpectation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
adc5906253 Apply Rails/PluralizationGrammar rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
Javi Martín
71d9ddd849 Apply rule to end files with a newline character 2019-09-10 20:02:15 +02:00
Javi Martín
cf9e36c767 Replace single quotes with double quotes
Most of these quotes were in the dashboard branch before we added the
rule for double quotes.
2019-09-10 19:21:03 +02:00