Commit Graph

2143 Commits

Author SHA1 Message Date
voodoorai2000
7d5b57aee2 Add counter of emails sent to newsletter preview 2018-10-30 17:07:31 +01:00
Javi Martín
74927f4ed6 Make Capybara check the page between comment votes
As pointed out in PR consul#2734:

"After clicking the first link, there's an AJAX request which replaces
the existing `.in-favor a` and `.against a` links with new elements. So
if Capybara tries to click the existing `.against a` link at the same
moment it's being replaced, clicking the link won't generate a new
request".

Making Capybara check the page for new content before clicking the
second link solves the problem.

This commit solves issues afecting both Madrid's fork and the original
CONSUL repo.
2018-10-29 11:15:03 +01:00
Javi Martín
f5bb3c64a1 Don't run specs if there are custom fallbacks
This spec depends on French falling back to Spanish and was failing on
forks using a different fallback.
2018-10-22 16:36:18 +02:00
Javi Martín
2e6644d513 Fix crash with no translation for default locale
When we were visiting a page showing the content of a record which uses
globalize and our locale was the default one and there was no
translation for the default locale, the application was crashing in some
places because there are no fallbacks for the default locale.

For example, when visiting a legislation process, the line with
`CGI.escape(title)` was crashing because `title` was `nil` for the
default locale.

We've decided to solve this issue by using any available translations as
globalize fallbacks instead of showing a 404 error or a translation
missing error because these solutions would (we thinkg) either require
modifying many places in the application or making the translatable
logic even more complex.

Initially we tried to add this solution to an initializer, but it must
be called after initializing the application so I18n.fallbacks[locale]
gets the value defined in config.i18n.fallbacks.

Also note the line:

fallbacks[locale] = I18n.fallbacks[locale] + I18n.available_locales

Doesn't mention `I18n.default_locale` because the method
`I18n.fallbacks[locale]` automatically adds the default locale.
2018-10-22 16:36:18 +02:00
Javi Martín
dbea577062 Follow naming conventions for HTML classes and IDs
We use underscores for IDs and hyphens for classes.
2018-10-22 16:36:18 +02:00
Javi Martín
f1ccdb87b1 Fix removing an option for legislation questions
We were allowing the `_destroy` field for translations, but not for the
options themselves.
2018-10-22 16:36:17 +02:00
Javi Martín
6952c9c9db Fix legislation options not being updated
We broke this behaviour by introducing translations and not allowing the
`id` parameter anymore.
2018-10-22 16:36:17 +02:00
Javi Martín
3db145d5db Simplify creating a process in questions specs 2018-10-22 16:36:17 +02:00
Javi Martín
6d6eb1f849 Fix ambiguous field in test 2018-10-22 16:36:17 +02:00
Javi Martín
7479223d59 Wrap translation fields in a div
This way we can show/hide that div when displaying translations, and we
can remove the duplication applying the same logic to the label, the
input, the error and the CKEditor.

This way we also solve the problem of the textarea of the CKEditor
taking space when we switch locales, as well as CKEditor itself taking
space even when not displayed.
2018-10-22 16:36:17 +02:00
Javi Martín
3b5a12b0ab Don't force translations for the current locale
Globalize creates a translation for the current locale, and the only way
I've found to change this behaviour is to monkey-patch it.

The original code uses `translation.locale` instead of
`Globalize.locale`. Since `translation.locale` loads the translation
with empty attributes. It both makes the record invalid if there are
validations and it makes it almost impossible to create a record with
translations which don't include the current locale.

See also the following convertations:

https://github.com/globalize/globalize/pull/328
https://github.com/globalize/globalize/issues/468
https://github.com/globalize/globalize/pull/578
https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize#blank-translations
2018-10-22 16:28:53 +02:00
Javi Martín
139cf769c6 Update widget cards translatable fields 2018-10-22 16:28:49 +02:00
Javi Martín
3c170f47d2 Update site customization pages translatable fields 2018-10-22 16:13:48 +02:00
Javi Martín
e0b9c1bfdd Update poll question answers translatable fields
We needed to bring back support for CKEditor in our translatable form,
which we had temporarily remove.

And now we support CKEditor in our translatable specs, and so we can
remove the duplicated specs for poll question answers.
2018-10-22 16:13:48 +02:00
Javi Martín
d1249d0b4f Update poll questions translatable fields
We need to replace ".title=" by ".title_#{locale}=" in one place because
for some reason globalize builds a new translation record when using the
latter but it doesn't build one when using the former.
2018-10-22 16:13:30 +02:00
Javi Martín
759de935ee Update polls translatable fields
The `:name` attribute is still allowed in the controller because some
forks use it when creating a poll from a budget.
2018-10-22 15:52:58 +02:00
Javi Martín
85701bd754 Update legislation questions translatable fields 2018-10-22 15:46:24 +02:00
Javi Martín
5bfc7ca2e3 Update legislation process translatable fields 2018-10-22 15:46:16 +02:00
Javi Martín
6278175f57 Update legislation drafts translatable fields
Updating it required reorganizing the form so translatable fields are
together.

We also needed to add a `hint` option to the form label and input
methods so the hint wouldn't show up for every language.

Finally, the markdown editor needed to use the same globalize attributes
as inputs, labels and hints, which adds a bit of duplication.
2018-10-22 15:44:14 +02:00
Javi Martín
01a254545f Update milestones translatable fields
Note the title field was hidden since commit 01b9aa8, even though it was
required and translatable. I've removed the required validation rule,
since it doesn't seem to make much sense and made the translatable
tests harder to write.

Also note the method `I18n.localize`, which is used to set the
milestone's title, uses `I18n.locale` even if it's inside a
`Globalize.with_locale` block, and so the same format is generated for
every locale.
2018-10-22 15:44:14 +02:00
Javi Martín
a326bcb0a1 Update admin notifications translatable fields
The same way we did for banners.

We needed to add new translation keys so the labels are displayed in the
correct language. I've kept the original `title` and `body` attributes
so they can be used in other places.

While backporting, we also added the original translations because they
hadn't been backported yet.
2018-10-22 15:43:56 +02:00
Javi Martín
71601bd3f8 Validate translations in banners
This change forces us to use nested attributes for translations, instead
of using the more convenient `:"title_#{locale}"` methods.

On the other hand, we can use Rails' native `_destroy` attribute to
remove existing translations, so we don't have to use our custom
`delete_translations`, which was a bit buggy since it didn't consider
failed updates.
2018-10-22 15:43:28 +02:00
Alberto
3878946c9e Merge pull request #2823 from consul/remove-guides
Removes guide feature
2018-10-18 13:19:33 +02:00
Javier Martín
e117218d68 Merge pull request #2977 from consul/backport-reenable_ckeditor_images
Bring back CKEditor images button
2018-10-17 20:21:18 +02:00
Javi Martín
6f96265a0b Bring back CKEditor images button
It was accidentally deleted in commit 914bfa6.

Note the following spec passes on my machine if we add a `sleep 0.1`
call in the `:wait_readable` part of ruby's `Net::Protocol#rbuf_fill`.
Otherwise, it hangs forever after clicking the `.fileupload-file` div,
which closes its window. It might be solved when upgrading rails,
capybara, selenium or chromedriver.

scenario "Allows images in CKEditor", :js do
  visit edit_admin_site_customization_page_path(custom_page)

  within(".ckeditor") do
    within_frame(0) { expect(page).not_to have_css("img") }

    expect(page).to have_css(".cke_toolbar .cke_button__image_icon")
    find(".cke_toolbar .cke_button__image_icon").click
  end

  within_window(window_opened_by { click_link "Browse Server" }) do
    attach_file :file,
                Rails.root.join('spec/fixtures/files/clippy.jpg'),
                visible: false
    find(".fileupload-file").click
  end

  click_link "OK"

  within(".ckeditor") do
    within_frame(0) { expect(page).to have_css("img") }
  end
end
2018-10-17 19:39:37 +02:00
Javi Martín
893f29a27a Fix flaky legislation question spec
The test was failing sometimes because of the sequence:

within('#side_menu') do
  click_link "Collaborative Legislation"
end

click_link "All"
expect(page).to have_content 'An example legislation process'
click_link 'An example legislation process'

Right after clicking the "Collaborative Legislation" link, the link 'An
example legislation process' is already available. So sometimes Capybara
might click the links "All" and 'An example legislation process' at more
or less the same time, causing the second link not to be correctly
clicked.

Making sure the "All" link doesn't exist anymore we guarantee Capybara
will wait for the previous AJAX request to finish before clicking the
next link.

Note the test to "Create Valid legislation question" is almost identical
but it doesn't fail because it doesn't use Capybara's JavaScript driver.
2018-10-17 15:54:59 +02:00
decabeza
dbf41421ed Removes guide feature 2018-10-17 14:58:29 +02:00
Raimond Garcia
710e5ae965 Merge pull request #2949 from consul/i18n-language-names
Display language name or language key
2018-10-10 11:45:04 +02:00
voodoorai2000
59b35156b1 Fix flaky spec
`I18n.available_locales=` does a little magic[1] and was causing some flakieness along the way, as the `:wl` locale persisted in future specs

Thanks for the heads up @javierm 👌

[1] https://www.rubydoc.info/github/svenfuchs/i18n/I18n%2FConfig:available_locales=
2018-10-09 22:15:05 +02:00
voodoorai2000
6f978b9f4e Fix portuguese specs 2018-10-09 18:32:59 +02:00
voodoorai2000
9d7042c5ae Adds missing language name translations 2018-10-05 18:08:47 +02:00
voodoorai2000
0a0261900c Display language name or language key
There where two issues with the current implementation:

- There was a possible duplication between looking up the language name in key "locale" and in key "i18n.language.name"

- The "default" option was not being picked up, as the fallback always returned the default locale's translation, "English"

With this implementation there is only a single place to put the language name: i18n.language.name. I think this place is easier to find and understand for Crowdin translators than a "locale" key hidden in general.yml

If the translation is not found we display the language key, instead of English, which makes more sense to me too 😌

Solution based on recent comments[1] on a related I18n issue

[1] https://github.com/svenfuchs/i18n/issues/365#issuecomment-419263847
2018-10-05 18:08:41 +02:00
Javier Martín
e4f99681f8 Merge pull request #2950 from consul/backport-improve_index_legislation_proposals
Allow select winner legislation proposals
2018-10-05 12:59:28 +02:00
Javi Martín
ea7d4e0996 Remove trailing whitespace 2018-10-05 12:21:37 +02:00
Javi Martín
0945f046a3 Avoid using xpath in specs
Using xpath is usually harder to read and more fragile.
2018-10-04 16:31:00 +02:00
Javi Martín
959270b0bb Separate setup, actions and expections in specs 2018-10-04 16:31:00 +02:00
Javi Martín
9c13f08c8e Show selected legislation proposals by default 2018-10-04 16:31:00 +02:00
Javi Martín
d9410a132a Always show filters for legislation proposals
As done in the rest of the application: we show the filters even if
there isn't any data to display.
2018-10-04 16:31:00 +02:00
Javi Martín
2fb5fb5fb2 Add missing newline characters 2018-10-04 16:31:00 +02:00
Javi Martín
81871a56f8 Simplify legislation process specs
We kill two birds with one stone and also make each line less than 100
characters long.
2018-10-04 16:30:59 +02:00
Javi Martín
7d69f2aaab Properly test order by ID
By default records are already ordered by ID, so we weren't checking the
ordering by ID functionality was working properly.

Making the records be ordered by title first makes the test a bit more
reliable.
2018-10-04 16:29:01 +02:00
Javi Martín
dc9cf5da55 Order by supports in descending order
Just as we do with confidence score, and as admins expect when they
order by received supports: the ones with more supports appear first.
2018-10-04 16:29:01 +02:00
Javi Martín
f1745f8040 Fix typo 2018-10-04 16:29:01 +02:00
Javi Martín
75d1ab1e52 Use AJAX requests to select legislation proposals
Now the interface is more similar to the one in budget investments.
2018-10-04 16:29:01 +02:00
Raúl Fuentes
a859de5d16 Test the selectable proposals 2018-10-04 16:29:01 +02:00
Javi Martín
ec18743251 Authorize resource after authenticating user
Just like it's done everywhere else in the application. Not doing so
means users who aren't logged in receive a "you aren't authorized"
message when they try to create a new legislation proposal instead of
being redirected to the login page.
2018-10-03 22:06:20 +02:00
María Checa
388c1a9bd9 Improved tests 2018-10-03 16:02:41 +02:00
María Checa
d73be15296 Added tests 2018-10-03 16:02:41 +02:00
Bertocq
52df63c2aa Add legislation proposal feature scenario to check random order is consistent with pagination 2018-10-03 13:46:32 +02:00
Bertocq
89b8e51a93 Add helper function to get legislation proposals list order on feature spec 2018-10-03 13:46:32 +02:00