Commit Graph

16 Commits

Author SHA1 Message Date
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
cdc166e830 Make it easier to distinguish counts and prices
With so many similar numbers, the tests were hard to follow. Besides,
we're now making these lines slightly shorter :).
2023-08-30 14:46:35 +02:00
Javi Martín
969e0014e5 Move budget result test to the model
We were testing that the `calculate_winners` method does not take the
price into account; we can do the same in a model test. We already have
a different system test to check that the price isn't displayed in the
view.
2022-08-25 14:31:51 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +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
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
6542c6f0b1 Merge pull request #3714 from consul/simplify_investment_creation
Simplify investments creation in specs
2019-09-23 17:56:43 +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
ffc50246c2 Apply explict RSpec/DescribedClass rubocop rule
We settled on using this style in commit 4cbe81a1, but didn't add the
rule enforcing this style and we didn't apply it to existing code.
2019-09-23 16:51:00 +02:00
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
Bertocq
2b85deabec Recalculate heading winners on incompatibility change
Why:

* We should recalculate winners also when an incompatible investment is flagged as compatible again

How:

* Removing the condition to recalculate that was checking only for a winner investment flagged as incompatible
* Extending the Budget::Result model spec to cover that new scenario
2017-07-10 14:24:55 +02:00
Bertocq
21864f3fb5 Increase Budget Result spec to check incompatible investments can't be winners
Why:

* A incompatible investment can't be chosen as a winner
* When a winner investment is marked as incompatible, winnersmust be recalculated and it can't be a winner

How:

* Increasing existing scenarios to include a incompatible investment
* Adding a new scenario where a winner investment gets flagged as incompatible
2017-07-03 15:59:01 +02:00
rgarcia
0b68f3c619 cleans up 2017-05-19 14:07:30 +02:00
rgarcia
65eb2bb160 adds budget result specs 2017-05-19 14:04:46 +02:00