Commit Graph

15065 Commits

Author SHA1 Message Date
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
Javi Martín
7c252750c9 Remove duplicated call to index customization
The statement executed the method twice if the `present?` condition was
true. If the condition was false, it executed it once anyway.

It's probably a typo and originally we probably meant we wanted to
execute the method if the method existed.
2019-08-27 17:22:22 +02:00
Javi Martín
3a2818ece5 Remove unused method
This method was not used since commit d0245059.
2019-08-27 17:22:22 +02:00
Javi Martín
e64289c5f9 Fix double quotes inside double quotes
The interpolation was being evaluated as a comment.
2019-08-27 17:22:22 +02:00
dependabot-preview[bot]
f7da0704a0 [Security] Bump nokogiri from 1.10.2 to 1.10.4
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.10.2 to 1.10.4. **This update includes security fixes.**
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.10.2...v1.10.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-11 21:22:15 +00:00
Javier Martín
072d53f8b8 Merge pull request #3674 from consul/remove_duplicate_translation_classes
Remove duplicate translation classes
2019-08-09 14:00:02 +02:00
Javi Martín
e500d15704 Use Translation classes consistently
We're moving the code for the phases translation class to the same place
in the code the other translation classes are: right after including the
Globalizable module.
2019-08-08 18:49:14 +02:00
Javi Martín
59478ef461 Remove duplicate Translation classes
We accidentally added them twice when rebasing the translations branch.
2019-08-08 18:49:13 +02:00
Javi Martín
648cdf1440 Fix CKEditor height in dashboard actions form
Not wrapping the editor in a `.ckeditor` div made it change height when
the editor was loaded. That caused a weird effect for users, and also
made some tests fail sometimes since the position of the "Add new
document" link might change right when capybara is clicking it.
2019-08-08 16:35:20 +02:00
Javier Martín
5ade66dfa4 Merge pull request #3663 from consul/custom_locales_check
Load custom locales after everything is loaded
2019-08-07 23:54:40 +02:00
Javi Martín
0b1a4907ac Load custom locales after everything is loaded
The line:

```
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
```

Was adding every locale under the `config/locales` folder, including the
ones inside `config/locales/custom/`. The files were loaded in the same
order as listed using `ls -f`.

So if the custom locales were loaded before the folder
`config/locales/#{I18n.locale}`, the default locales would override the
custom ones, and we want the custom locales to override the default
ones so CONSUL is easier to customize.
2019-08-07 22:05:01 +02:00
Javier Martín
1296069092 Merge pull request #3635 from consul/remove_custom_dashboard_task
Remove custom dashboard task
2019-08-07 22:00:14 +02:00
Javier Martín
b7f183f297 Merge pull request #3608 from consul/remove_system_total
Remove system recounts in the admin section
2019-08-07 21:15:34 +02:00
Javi Martín
d981e23cd7 Remove custom dashboard task
It was made for Madrid's repository, but was accidentally added to
CONSUL as well.
2019-08-07 20:37:02 +02:00
Javi Martín
0b55097820 Remove system count from old booth assigments
This number was not the important one; the important one is the one
given by the recounts.

Note we're also removing the votes by date, since they're also system
votes.
2019-08-07 20:31:45 +02:00
Javi Martín
45376d1e49 Fix indentation 2019-08-07 20:31:45 +02:00
Javi Martín
aa759e1af8 Simplify recounts code
Now the code is the same as the code in the poll booth assignment page.
2019-08-07 20:31:45 +02:00