Commit Graph

14352 Commits

Author SHA1 Message Date
Javi Martín
d639cd587a Remove unnecessary uniq calls
The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
2019-09-10 22:27:33 +02:00
Javi Martín
9fb1d7df31 Remove obsolete ScopeArgs rubocop rule
This rule doesn't make sense with Rails 5 anymore, since breaking it
will raise an error.
2019-09-10 22:27:33 +02:00
Javi Martín
ea17256e3a Remove gemspec rubocop rules
We don't have a gemspec file, so we don't need these ones.
2019-09-10 22:27:33 +02:00
Javi Martín
9d566a2250 Remove most performance rubocop rules
For performance purposes, we need to find bottlenecks in our
application. Optimizing the performance of small methods doesn't make
the application faster.

I've kept a few cops because applying these ones IMHO make the code
easier to read.
2019-09-10 22:27:33 +02:00
Javier Martín
274fd1af4d Merge pull request #3636 from consul/change_basic_rubocop_rules
Change basic rubocop rules
2019-09-10 22:27:08 +02:00
Javi Martín
2243809d2e Move basic RSpec rubocop rules to basic cops
These are rules we were already applying.

We've excluded the `factories` folder for some rules because there's a
factory defining a `context` attribute, which rubocop thought was the
`context` RSpec keyword.
2019-09-10 21:43:39 +02:00
Javi Martín
59e107e565 Apply RSpec/HookArgument rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
9541ce892c Apply Bundler rubocop rules
We're not using the InsecureProtocolSource rule because I don't feel
it's necessary.
2019-09-10 21:43:39 +02:00
Javi Martín
c05b9c2aac Apply Capybara/CurrentPathExpectation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
969a4e21c9 Apply RSpec/RepeatedExample rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
044eabd7ef Apply Rspec/LetSetup rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
58ba517717 Apply RSpec/ExampleWording rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
0788925c1b Apply Rails/Validation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
27c73c22ea Configure Rails/UnknownEnv rubocop rule
We use staging and preproduction environments, which are not valid by
default.

This rule is useful because misspelling the name of an environment might
otherwise go unnoticed.
2019-09-10 21:43:39 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
daa86ca3fc Apply Rails/RequestReferer rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
a5ba13b599 Apply Rails/Presence rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
adc5906253 Apply Rails/PluralizationGrammar rubocop rule 2019-09-10 21:43:38 +02:00
Javier Martín
1821a18c61 Merge pull request #3631 from consul/add_spacing_rules
Add rubocop spacing rules
2019-09-10 21:42:44 +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
Javier Martín
c7f64f8493 Merge pull request #3629 from consul/rubocop_rules
Apply Rubocop rules
2019-09-10 20:48:30 +02:00
Javi Martín
f74971060b Apply SpaceInHtmlTag ERB Lint rule 2019-09-10 20:02:15 +02:00
Javi Martín
ee8426c5b5 Indent with spaces instead of tabs 2019-09-10 20:02:15 +02:00
Javi Martín
c62da726b8 Apply SpaceAroundErbTag ERB Lint rule 2019-09-10 20:02:15 +02:00
Javi Martín
24359f8152 Remove extra space in HTML tags 2019-09-10 20:02:15 +02:00
Javi Martín
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
Javi Martín
47b2c42a1d Apply IndentationConsistency rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
e252d82cdb Apply IndentationWidth rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
17c36c6c6c Apply NotToNot rubocop rule 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
347fc21cf0 Fix trailing whitespace 2019-09-10 19:21:03 +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
Javi Martín
5c5d798590 Don't use Include in rubocop configuration file
The Rakefile and config.ru files are now included by default, and the
behaviour of `Include` changed in Rubocop 0.56.0 (see rubocop's pull
request 5882) so now it **only** includes the files defined there, while
in the past it included those files in addition to the default files.
2019-09-10 19:21:02 +02:00
Javier Martín
48b128744c Merge pull request #3678 from consul/fix_nan_score
Fix Infinity exceptions in hot score calculator
2019-09-10 17:51:23 +02:00
Javier Martín
e25d0ebc44 Merge pull request #3684 from consul/dynamic_from_mailer
Evaluate mailer from address at runtime
2019-09-10 17:08:46 +02:00
Javier Martín
f18ed2c595 Merge pull request #3650 from consul/fix_votation_spec
Fix flaky votation type specs
2019-09-10 16:40:51 +02:00
Javi Martín
53abc57578 Fix Infinity exceptions in hot score calculator
There was a rare case we've found on some Travis builds where the system
time suddenly moved back to the past a couple of tenths of a second,
meaning `Time.current - resource.created_at` returned a negative number,
which lead to a division by zero.
2019-09-10 16:00:21 +02:00
Javi Martín
852d3b0ed6 Extract methods to calculate hot score period 2019-09-10 16:00:21 +02:00
Javi Martín
66da02f1de Evaluate mailer from address at runtime
We're reading the value from the database, but the
`ApplicationMailer.default` method is evaluated when the application is
started. So if we don't use a Proc, we'll need to restart the server
every time we change the value in the database, or else the old value
will still be used.

Using a Proc makes sure the mailer from address is evaluated at runtime,
so emails are sent using the from address currently defined in the
database.

The same situation took place using the devise mailer. Now we don't need
to check for the settings table being present because the Proc in the
devise initializer won't be evaluated before the settings table is
created and populated.
2019-09-10 15:59:59 +02:00
Javi Martín
87884da4e2 Avoid race conditions in votation type tests
We were performing an AJAX request and then a "normal" request without
checking the AJAX request had finished. Sometimes it resulted in the
normal request finishing because the AJAX request did, causing the test
to fail.
2019-09-10 15:58:28 +02:00
Javi Martín
b48678e332 Use have_link instead of have_css("a") 2019-09-10 15:58:28 +02:00
Javi Martín
9e522e713b Remove commented votation tests
They don't pass, and they aren't maintained anymore.
2019-09-10 15:58:28 +02:00
Javier Martín
233e65f18c Merge pull request #3687 from consul/reduce_proposals_in_pagination
Reduce the number of proposals in pagination spec
2019-09-10 15:57:57 +02:00
Javier Martín
67ae821360 Merge pull request #3686 from consul/lowercase_tags
Fix flaky specs for uppercase tags
2019-09-10 15:04:17 +02:00
Javi Martín
1c071b5ff0 Reduce the number of proposals in pagination spec
We're getting a failure on Travis in one of these tests. Debugging shows
the AJAX request rendering the first page (after clicking the "Previous"
link) takes too long and sometimes it exceeds Capybara's timeout.

After running the test thousands of times, the only way I've found to
clearly reduce the number of times the test fails is to reduce the
number of records shown on the first page. Other experiments, like
adding an `includes(:author)` to the query getting the proposals in the
controller, or adding `author: user` to the `create_list` part of the
test (so only one author needs to be fetched when rendering the
proposals) show inconsistent results regarding performance.

Note we still need at least 10 proposals for the test for several users,
to guarantee two users will never get the same records during the test
(or at least the probability they get the same records is one in
millions).
2019-09-10 15:01:36 +02:00
Javier Martín
64166b34a2 Merge pull request #3685 from consul/less_records_in_tests
Create less headings in budget investment tests
2019-09-10 14:58:54 +02:00
Javier Martín
698b3dc4ee Merge pull request #3683 from consul/capybara_webmock
Avoid Net::ReadTimeout errors in tests
2019-09-10 14:37:19 +02:00
Pierre Mesure
7fc4106780 Cleaning a few lines 2019-09-08 22:39:01 +02:00
Pierre Mesure
d317af572c Set locales in test environment to avoid failed specs 2019-09-08 22:39:00 +02:00