Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
5d362ced1f Fix duplicate HTML IDs in comment forms
Since there were many on the page, the resulting HTML was invalid.
2020-05-12 23:57:57 +02:00
Javi Martín
faefb52972 Use the same code to add comments and replies 2020-05-12 23:57:57 +02:00
Javi Martín
4627372a62 Use a <ul> tag for a list of comments
We were using a <ul> tag for a single comment, where the first element
of the list was the comment itself and the second element was the list
of replies.

IMHO it makes more sense to have a list of all comments, where every
element is a comment and inside it there's a list of replies.

We're also rendering the list even if it has no children so it's easier
to add comments through JavaScript. Then we use the :empty CSS selector
to hide the list if it's empty. However, since ERB adds whitespace if we
structure our code the usual way and current browsers don't recognize
elements with whitespace as empty, we have to use the `tag` helper so no
whitespace is added.
2020-05-12 23:57:16 +02:00
Javi Martín
bedd879025 Remove redundant show/hide screen reader texts
These texts are redundant since we added the same texts for everyone in
commit 6b85ed87.
2020-05-12 23:23:01 +02:00
Javi Martín
41b9d2ba01 Simplify code to show/collapse comment replies
Tests are also a bit easier to read, even though we need to use the
`text:` option to find links because otherwise the text in the hidden
`<span>` tags will cause `click_link` to miss the link we want to click.

Here's an explanation by one of Capybara's authors:
https://github.com/teamcapybara/capybara/issues/2347#issuecomment-626373440
2020-05-12 23:23:01 +02:00
Javi Martín
255e56c0f2 Simplify toggleClass call
This method accepts several classes as arguments, so there's no need to
call it twice.
2020-05-11 16:09:23 +02:00
Javi Martín
06b7c6dbd3 Simplify comment partial variables
We were passing around many variables to condition the way we display
the comment. However, in the end we only had one place where these
variables were used: valuation. So we can make everything depend on the
valuation variable.
2020-05-11 16:09:23 +02:00
Javi Martín
573f861ad1 Don't use comment_flags to cache comments
Flagging a comment automatically updates the comment, so the cache
expires anyway, making the `comment_flags` variable redundant.
2020-05-11 16:09:23 +02:00
Javi Martín
fbaa5c2388 Remove unused commentable tree partial
It was created in commit 83d254ad, but it was never used, since the
commit creating it removed the code rendering the
`budgets/investments/comments` partial, which this partial was supposed
to replace.
2020-05-11 16:09:23 +02:00
Javier Martín
2fee7099ae Merge pull request #3998 from rockandror/ckeditor-browser-history-back
Destroy and intialize ckeditor on browser history back
2020-05-11 14:29:39 +02:00
Senén Rodero Rodríguez
3d0ce57f03 Destroy and intialize ckeditor on browser history back
When a page with ckeditor is restored from browser cache by using browser
history back feature application was trying to re-initialize it but this was
throwing some javascript errors that left ckeditor useless. The ckeditor user
interface seemed to be loaded correctly but editor contents was not shown
and ckeditor locked.

This solution is about destroying all ckeditor instances on page before
leaving it and force the reinitialization after Turbolinks restored the cache.
Inspiration here [1].

There is a similar patch to make it work with Turbolinks 5.x versions [2].

  [1] https://github.com/galetahub/ckeditor/issues/575#issuecomment-132757961
  [2] https://github.com/galetahub/ckeditor/issues/575#issuecomment-241185136
2020-05-11 11:15:45 +02:00
Javier Martín
4b9a05d4d8 Merge pull request #3997 from rockandror/remove_ajax_complete
Do not run all javascript after every ajax call
2020-05-09 13:43:08 +02:00
Senén Rodero Rodríguez
c2b9377055 Extract duplicated code to method 2020-05-09 08:17:56 +02:00
Senén Rodero Rodríguez
70a9fb7355 Do not call initialize_modules after every ajax call
We were calling initialize_modules after every ajax call only to apply the
application javascript to new elements added though ajax calls, this is not
always needed because some ajax calls do not add new elements to the user
interface so there is no new elements to initialize. This technique was working
fine in most cases but was causing different kind of problems at some pages where
some elements where being unnecessarily reinitiliazed causing the execution of the
element associated scripts as many times as the element was initialized. This fix
should relief a little bit of work to users browsers.

After this change we had to fix some pieces of javascript:

Regarding LegistationAnnotatable module, since we are not re-initializing Annotator
app we cannot destroy it so now we only need to insert the new annotation into annotator
interface to keep it properly updated.

Regarding Comments module, we do not need anymore the initialization check because this
code only will be fired once now we do not launch application initialization after ajax
calls. Also, when a new comment is created its added to the DOM through AJAX and include
some elements that needs javascript initialization to work. By using
"Delegated event handlers" [1] new comments will be initialized automatically when added.

[1] https://api.jquery.com/on/#direct-and-delegated-events
2020-05-09 08:17:55 +02:00
decabeza
8e01b11569 Move conditional into shared banner partial
To avoid always writing if has_banners? every time the partial is used it has been moved within this partial.
2020-05-08 12:00:03 +02:00
Javier Martín
dcf0a50b73 Merge pull request #3960 from luchiago/chore-bump-ruby-version-docker
Update ruby version docker
2020-04-30 20:57:20 +02:00
Lucas Hiago
9bad819273 Update ruby version on dockerfile 2020-04-30 15:30:16 -03:00
Senén Rodero Rodríguez
0ec1f6a4f8 Do not update form location fields when marker is not defined 2020-04-30 19:44:23 +02:00
Javi Martín
a20622e2fa Allow remote translation tests to be run offline
The method `available_locales` in
`RemoteTranslations::Microsoft::AvailableLocales` needs to execute a
request to an external server in order to work, meaning it will fail if
the machine its executed on doesn't have an internet connection.

So we're stubbing the method in the tests using it.
2020-04-28 15:45:50 +02:00
Javi Martín
e7fcca9b47 Check remote translations locales at runtime
We were evaluating its value when the server starts. On production
enviroments, that could mean weeks or months before the available
locales are checked again, and so it would be possible to use a list
which is no longer in sync with the list provided by microsoft.
2020-04-28 15:45:32 +02:00
Javier Martín
240cad793f Merge pull request #3990 from consul/contributing
Update contributing
2020-04-28 12:34:42 +02:00
Javier Martín
ad94738031 Merge pull request #3985 from consul/dynamic_find_by
Increase severity of DynamicFindBy rubocop rule
2020-04-28 12:27:20 +02:00
Javier Martín
586bcfee62 Merge pull request #3633 from consul/use_rails_5.1_methods
Use Rails 5.1 methods to simplify code
2020-04-28 12:25:58 +02:00
decabeza
b5b103ac67 Update contributing 2020-04-28 10:27:30 +02:00
Javi Martín
f2cdc31786 Use ActiveRecord::Relation#count with a block
This method used to ignore the block but in Rails 5.1 it uses
Enumerable#count.

See https://github.com/rails/rails/pull/24203/commits/58772397
2020-04-27 19:26:37 +02:00
Javi Martín
08679bc9cc Use link_to instead of content_tag :a 2020-04-27 19:26:37 +02:00
Javi Martín
749428d93f Replace content_tag with new tag builder syntax
One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
2020-04-27 19:26:37 +02:00
Javi Martín
fa070f326e Remove unnecessary content_tag calls
We're usually using HTML tags in views instead.
2020-04-27 19:26:37 +02:00
Javi Martín
3ba8b05cbb Use Date#all_day in DirectMessage.today
The method `Date#all_day` was added in Rails 5.1, and returns the same
interval we were using while it makes the code simple.
2020-04-27 19:26:37 +02:00
Javi Martín
4e76f90afd Simplify LEFT JOIN using ActiveRecord#left_joins
This method is available since Rails 5.0.
2020-04-27 19:26:37 +02:00
Javier Martín
d3fa00b1e6 Merge pull request #3987 from rockandror/fix_source_translations
Fix source translations
2020-04-27 15:19:24 +02:00
Senén Rodero Rodríguez
1bd4915fbb Apply fixes suggested by Crowdin translators
Some Crowdin translators noticed about some errors at source language
strings (English).
2020-04-27 14:27:01 +02:00
Javier Martín
b65b523d1d Merge pull request #3982 from rockandror/fix_flakies_vote_multiple_times
Mitigate flaky specs for vote multiple times
2020-04-24 21:12:18 +02:00
Javi Martín
e71052a5f1 Increase severity of DynamicFindBy rubocop rule
Back in commit 49e55b4d we lowered its severity because there were a
few false positives. Back then, I didn't realize we could just whitelist
the methods causing false positives.

Thanks taitus for the tip.
2020-04-24 18:55:42 +02:00
taitus
f60d307a59 Mitigate recurrent flaky specs for voting comments 2020-04-24 18:16:40 +02:00
Javier Martín
c0e7eec882 Merge pull request #3621 from consul/upgrade_to_rails_5.1
Upgrade to Rails 5.1
2020-04-24 17:51:51 +02:00
Javi Martín
7e702fc7ed Fix DB corruption in system tests after exceptions
This is a known bug in Rails, fixed in the Rails 5.2 and Rails 6.x
branches:

https://github.com/rails/rails/pull/32293/commits/5c4e1338
2020-04-24 15:43:54 +02:00
Javi Martín
a103b5392e Use more consistent parameter names
I incorrectly used "text" as variable name in commit 2cdc6a1b. In
similar places, we use `label`. We also use named parameters when only
`with:` is provided.
2020-04-24 15:43:54 +02:00
Javi Martín
5b97b20f96 Wait for CKEditor to load in specs
Some specs involving CKEditor were failing sometimes in the Rails 5.1
branch. The reason why these specs pass with Rails 5.0 but fail with
Rails 5.1 are unknown. On my machine the tests pass when precompiling
the assets, which makes me think it's related to the way Rails handles
them, but it might have nothing to do with it.

The only (apparently) 100% reliable solution I've found is to wait for
CKEditor to load before trying to fill it in. After running the tests on
my machine hundreds of time, I didn't get a single failure.
2020-04-24 15:43:54 +02:00
Javi Martín
688aa88366 Make migrations independent of globalize
There are two reasons for this change:

1. Past migrations depending on models will not work once a model is
removed, and they won't work if we remove Globalize either
2. We were getting a conflict in the schema file; when run under Rails
5.0, these migrations were generating a different schema than in Rails
5.1, due to the way the `create_translation_table!` method handles the
`id: :serial` attribute.
2020-04-24 15:43:54 +02:00
Javi Martín
37361a6f3d Replace render :nothing with head :ok
Using `render :nothing` was deprecated, but we never noticed it because
we didn't have a test for the action using it. In Rails 5.1, it raises
an exception.

Using `head :ok` and adding a test for this scenario solves the issue.
2020-04-24 15:43:54 +02:00
Javi Martín
6c0365d004 Fix moving CKEditor dialog in specs
CKEditor repositions the dialog to attach an image after showing it. If
its position changes right when Capybara is trying to click the "Upload"
link, the click does not work properly.

I haven't found a way to check the dialog has stopped moving, so I've
chosen to force its position to the top.

Without this change, this test failed a lot on my machine when using
Rails 5.1, both with an "iframe ckeditor" and an "inline ckeditor".
However, it didn't fail when using Rails 5.0.
2020-04-24 15:43:54 +02:00
Javi Martín
e316ad9c96 Bump byebug to version 11.1.1
Rails 5.1 updated the `method_source` dependency, which is incompatible
with pry 0.12.x (which some developers are using), and upgrading pry and
pry-byebug requires a more recent version of byebug.
2020-04-24 15:43:54 +02:00
Javi Martín
e6c747c96c Only load seeds once while testing
Since we use transactions now for every test, we can seed the database
at the beginning, and then it will go back to this state before a test
is executed.

Running the test suite is now considerably faster. On my machine, we
save a quarter of second per system test, meaning we save several
minutes for the whole suite.
2020-04-24 15:43:54 +02:00
Javi Martín
1c8a49615a Fix references to Capybara.app_host
We were manually setting `http://www.example.com`. However, Capybara now
uses `http://127.0.0.1`.

While we could change the code to use `127.0.0.1`, I think directly
using `Capybara.app_host` makes it easier to realize what the code is
doing. And, particularly, now it's clear the host has nothing to do with
our `Setting["url"]`, which by default points to `www.example.com` as
well.
2020-04-24 15:43:54 +02:00
Javi Martín
9427f01442 Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because
between tests we now rollback transactions instead of truncating the
database.
2020-04-24 15:43:54 +02:00
Javi Martín
12774c7484 Replace attribute_changed? in after callbacks
This method is deprecated in Rails 5.1 because its behavior will be
different in `before` and `after` callbacks.

We're replacing the deprecated `attribute_changed?` and `attribute_was`
methods with `saved_change_to_attribute?` and
`attribute_before_last_save` during `after_save` callbacks.

https://github.com/rails/rails/pull/32835/
2020-04-24 15:43:54 +02:00
Javi Martín
c6a8aa1301 Replace attribute_changed? in before callbacks
This method is deprecated in Rails 5.1 because its behavior will be
different in `before` and `after` callbacks.

Here we're replacing the deprecated `attribute_changed?` and
`attribute_was` with `will_save_change_to_attribute?` and
`attribute_in_database` during `before_save` callbacks.

https://github.com/rails/rails/pull/32835/
2020-04-24 15:43:54 +02:00
Javi Martín
1118c732f1 Bump acts-as-taggable-on to 6.0.0
Rails 5.1 introduced certain changes in the way a record is touched when
the counter cache option is enabled in a belongs to association.

We need to upgrade acts-as-taggable-on so it keeps changing the
`updated_at` attribute when a new tag is added to a record.

Note we now need to reload the records in some cases to get the
`context_tag_list` method to return what we expect. Methods like
`context_tags` however work properly with no need to reload the record.
2020-04-23 18:49:43 +02:00
Javi Martín
3526aef1e4 Remove callback terminator initializer
We no longer need it since this is the default behavior in Rails 5.1.
2020-04-23 18:49:43 +02:00