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
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.
* Adapt translatable spec helper method to work with budget investments
* Remove old attributes from strong parameters
* Add missing locales to admin.yml and budgets.yml
* Change SpendingProposal.title_max_length and
SpendingProposal.description_max_lenght to Budget::Investment methods
* Add budget investment translatable attribute translations
We were showing only the ones being shown in the current page because
we were modifying `@investments` using a method which used
`@investments`, and we were calling that method twice.
There are many possible solutions: using a local variable to store the
result of the `investments` method, modifying `@investments` after
modifying `@investments_map_coordinates`, ... I've used the one which in
my humble opinion is a bit less fragile: not using `@investments` inside
the `investments` method. That way, the `investments` method will always
return the same result.
Note `stub_const("Budgets::InvestmentsController::PER_PAGE", 2)`
wouldn't work because `Budgets::InvestmentsController` isn't loaded when
that line is executed. So we need to load it. Instead of requiring the
file, using `#{Budgets::InvestmentsController}` seems to be an easier
solution.
We were filtering by winners investments for finished budget without
having in consideration other filters.
We want the default filter to be `winners` for finished budgets.
By using a random seed value smaller than 1, we solve the previous
situation[1] in a simpler way
This test is now obsolete.
It’s hard to write a tests to verify that even with a big seed in
params, we will covert it to a float smaller than 1.
We should refactor these `set_random_seed` methods into a nice model or
controller concern and test it thoroughly
[1]
https://github.com/AyuntamientoMadrid/consul/commit/ba3bf11526fc6ce9c66f
647c414946c61ff945fe
We are trying out a modulus function to return investments in random
order https://github.com/consul/consul/pull/2131
However we ran into the gotcha of having a seed value too big for the
modulus function to work as expected
If the seed is bigger than the investment id, the records are returned
ordered by id
By dividing the seed by a big number, this problem seems to get fixed