Commit Graph

14352 Commits

Author SHA1 Message Date
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
Javi Martín
bddfee2b86 Remove system count column for old polls
System count isn't a relevant number because the important one is the
number of votes counted by poll officers. We're still maintaining it for
a month in case poll officers would like to review the results.
2019-08-07 20:31:45 +02:00
Javier Martín
4b51ab4b6a Merge pull request #3622 from consul/use_dynamic_factories
Use dynamic attributes in factories
2019-08-07 20:31:25 +02:00
Javi Martín
c2869f4887 Move Rails/RelativeDateConstant to basic cops
The reason for this rule is similar to dynamic factories: we want
dynamic dates to be evaluted relative to the current time, and not
relative to the moment the application was loaded.
2019-08-07 19:43:59 +02:00
Javi Martín
fc1a89e966 Use dynamic attributes in factories
Static attributes are deprecated since factory bot 4.11; we haven't
upgraded yet but now we're ready to do so:

https://thoughtbot.com/blog/deprecating-static-attributes-in-factory_bot-4-11
2019-08-07 19:43:57 +02:00
Javi Martín
444fc524f7 Use the AttributeDefinedStatically rubocop rule
Factory bot has stopped supporting dynamic attributes, and we'll have to
change all factories before upgrading.

In order to apply the rubocop rule, we need to bump rubocop-rspec to its
latest version.
2019-08-07 19:41:45 +02:00
Javi Martín
61be48a6c6 Remove unused and obsolete rubocop rules
These rules are now defined under `Style/`. However, we don't really use
them, so they add noise to the rubocop configuration file without
solving any issues we actually have.
2019-08-07 19:41:45 +02:00
Javier Martín
46873fe251 Merge pull request #3620 from consul/fix_migrations
Use Rails 5.1 conventions in migrations and specs
2019-08-07 17:12:39 +02:00
Javier Martín
2ccfa5b049 Merge pull request #3643 from consul/fix_notifiable_comment
Fix flaky notifiable specs
2019-08-07 16:38:05 +02:00
Javi Martín
ae98dbf683 Use Rails 5.1 conventions in tests params 2019-08-07 15:50:00 +02:00
Javier Martín
0610991741 Merge pull request #3644 from consul/fix_flaky_proposals_spec
Fix flaky spec: Proposals Search Reorder results maintaing search
2019-08-07 15:40:45 +02:00
Javi Martín
9cff2ac56b Improve expectations in notifiable specs
Sometimes during this test some comments are not created (so far we
don't know why), but since all comments had the same text, we didn't
notice when checking the text of the comment was on the page.
2019-08-07 14:19:14 +02:00
Javi Martín
57bda006b5 Don't click two places at the same time
When clicking the button "Search", the link "newest" is already present,
so capybara might click the "newest" link before the "Search" request is
finished, leading to unexpected results.

Checking the page to make sure the "Search" request has finished before
clicking the "newest" link solves the problem.
2019-08-07 14:18:50 +02:00