Commit Graph

14280 Commits

Author SHA1 Message Date
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
Javi Martín
49751f46ec Fix tests for uppercase tags
The tests in the `spec/lib/graphql_spec.rb` failed sometimes because
creating a record with a tag list of ["health"] when both "health" and
"Health" tags exist might assign either one of them. These tests usually
pass because we create two records and just by chance usually one of the
records gets one tag and the other one gets the other tag. However, the
test was written as if we expected the first record to get the first tag
and the second record to get the second tag, while very often the tests
were passing because the first record got the second tag and the second
record got the first tag. And when both records get the same tag, the
tests fail.

So I've changed these tests to tags are assigned directly and, since we
want to test the `tag_list` method, I've also added some tests to the
Tag model, which reflect the current behaviour: a random tag is assigned
when several tags with the same case-insensitive name exist.

Another option to assign the right tag to the record we're creating
would be to add `ActsAsTaggableOn.strict_case_match = true` to an
initializer. However, that would also create new tags on the database
when we accidentally assign a tag like "hEaLth" (like in the test we add
in this commit). Ideally we would have a strict case match for existing
tags and a non-strict case match for new tags, but I haven't found a way
to do it.
2019-09-07 16:43:41 +02:00
Javi Martín
b5d25134d4 Create less headings in budget investment tests
We don't need to create a heading every time we create an investment; we
can use an existing one by default.

Some tests are now much faster and don't fail on Travis due to reaching
Capybara's timeout anymore.
2019-09-07 13:26:52 +02:00
Javi Martín
8bb5462253 Use capybara-webmock to avoid external requests
The images from OpenStreetMap take a while to load, sometimes even
causing Net::ReadTimeout errors if the internet connection is slow. It's
happened a lot recently on Travis builds.

Using capybara-webmock we guarantee the test suite doesn't fail due to
network issues.
2019-09-07 13:09:05 +02:00
Javier Martín
1f0a4cd875 Merge pull request #3657 from consul/precompile_ckeditor_dialogs
Precompile CKEditor dialog plugins
2019-09-07 13:08:23 +02:00
Javier Martín
183066d003 Merge pull request #3675 from consul/dependabot/bundler/nokogiri-1.10.4
[Security] Bump nokogiri from 1.10.2 to 1.10.4
2019-09-07 00:19:29 +02:00
Javi Martín
b05e881eee Precompile CKEditor dialog plugins
In some cases, in the production environment the dialogs for links,
images and tables didn't work, because these plugins were not
precompiled.
2019-09-06 22:20:22 +02:00
Javier Martín
1cff08d44d Merge pull request #3628 from consul/render_partial
Simplify calls to render partial
2019-09-04 15:47:21 +02:00
Javi Martín
911fe4e481 Simplify calls to render partial
We're also adding a bit of consistency, since most of our calls to
partial rendering omit the `partial` and `locals` keys.
2019-09-04 15:00:36 +02:00
Javier Martín
6923cdda89 Merge pull request #3641 from consul/fix_ckeditor_height
Fix CKEditor height in dashboard actions form
2019-09-04 14:58:41 +02:00
Javier Martín
9b7ce9e15f Merge pull request #3618 from consul/fix_date_today
Use Date.current and Time.current
2019-09-04 14:44:59 +02:00
Javi Martín
71bad63226 Remove DateTime.parse usage
While the correct usage would require an `in_time_zone` call, the code
can be simplified and the relationship between the current date and the
last `proposal.created_at + index.days` is now a bit easier to notice.

We use the beginning of the month as the date of the first action
because we expect all 8 actions to be created on the same month.
2019-08-28 20:32:40 +02:00
Javi Martín
a27ada662d Move Rails/Date and Rails/TimeZone to basic cops
Using Date.today and Time.now is a common mistake which might lead to
obscure bugs. Now we're making sure we'll receive a warning when a pull
request uses these methods.
2019-08-28 20:32:40 +02:00
Javi Martín
c574a4d93a Fix DirectMessage.today on different time zones
The dates are saved on UTC times on the database. So, for example,
if living in West Australia, `Date.current.beginning_of_day` will be
stored as UTC's yesterday at 15:15:00, while `Date.current.end_of_day`
will be stored as UTC's today at 15:14:59.

When we use the `DATE` database function, PostgreSQL will select the
records with the same UTC date as the current UTC date. However, we need
the records with the same application date (as defined in
`config.time_zone`) as the current application date. The test passed
(for us) because we were using `beginning_of_day + 3.hours` to make sure
we were creating records when the date in Madrid was the same as the UTC
date.

Using a ruby interval for the time condition solves the problem.
2019-08-28 20:32:40 +02:00
Javi Martín
f031d1289f Fix confusing time zone terminology
So now, application zone is the one defined in `config.time_zone`, and
system zone is the one in the computer where the application is running.
2019-08-28 20:32:40 +02:00
Javi Martín
a21240b230 Use Date.current and Time.current
Using Date.today and Time.now might lead to inconsistencies if the time
zone the application uses is not the same as the system time zone.
2019-08-28 20:32:40 +02:00
Javier Martín
158f59ce0d Merge pull request #3630 from consul/fix_typos
Fix typos and remove unused code
2019-08-28 20:25:50 +02:00
Javi Martín
2fcf7c9d25 Remove unused module
The name of this file should be `settings_helper.rb` (which already
exists), and the method `setting_for_widget` was never used anywhere.
2019-08-27 17:22:22 +02:00
Javi Martín
6ab2e5c16c Add missing quotes for HTML attribute 2019-08-27 17:22:22 +02:00
Javi Martín
4ab535dec4 Remove comma inside a HTML tag
The typo was detected thanks to erb-lint SpaceInHtmlTag rule.
2019-08-27 17:22:22 +02:00
Javi Martín
29da91a082 Fix untranslated texts
I've also renamed the key for the settings title so the `<h1>` gets the
`title` key, as done in other sections in the admin.
2019-08-27 17:22:22 +02:00
Javi Martín
06be5e132f Fix label in form to add own answer
The label text was always in English, and it wasn't associated with any
input field.

The `SecureRandom` part is a quick hack so we don't get duplicate IDs.
Using "your_answer_#{question.id}" might work as well, but right now I'm
not sure if the form is sometimes rendered twice for the same question.
2019-08-27 17:22:22 +02:00
Javi Martín
612e5ad832 Remove unused trackers form
This file was probably generated automatically and we forgot to remove
it. We never use it; the edit action includes its own form.
2019-08-27 17:22:22 +02:00