Commit Graph

66 Commits

Author SHA1 Message Date
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
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
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
Paweł Świątkowski
d99875cde2 Get search dictionary based on I18n.default_locale (merge pull request #3856)
Implementation tries to be open for further extensions, such as deciding on
search dictionary based on configuration option or by locale set for
given user.
2020-04-12 14:22:36 +02:00
Julian Herrero
69838c78b9 Revert "Stop using Knapsack Pro"
This reverts PR https://github.com/consul/consul/pull/3812
2019-11-06 18:58:05 +07:00
Julian Herrero
5b3d40ce8e Stop using Knapsack Pro 2019-11-04 16:58:06 +07:00
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +02:00
Javi Martín
cc76432a97 Use Time.current when freezing time
I was using Time.now because that's what Rails actually does, but we get
a warning by rubocop.
2019-10-22 17:37:51 +02:00
Javi Martín
6c45d21626 Avoid using Time.now and Date.today in zone tests
We've got a rubocop rule preventing us from using them, and the tests
are easier to read this way.
2019-10-22 17:37:48 +02:00
Javi Martín
0f2a96979e Don't use UTC as application zone in time zone tests
It was a bit confusing, since Travis uses UTC as the system zone, while
most application zones are not UTC.
2019-10-10 02:35:20 +02:00
Javi Martín
211398bd9d Use a more expressive name for time zone tests
"With different time zone" didn't clarify which time zone was different
nor what it was different to.
2019-10-10 02:34:51 +02:00
Javi Martín
41c99d9b27 Let Globalize use I18n locale
This is a mistake I made in commit f2ef27d3. Back then I thought we
needed to keep Globalize.locale and I18n.locale in sync, but the truth
is it automatically happens when setting Globalize.locale to nil.

So now we can use I18n.with_locale (at least in the tests) and forget
about Globalize, which will make it easier to switch to Mobility in the
future.
2019-09-23 18:01:44 +02:00
Javi Martín
eb7a052207 Simplify tests using delayed_job
Among other advantages, now we can run these tests with
`rspec --tag delayed_jobs`.
2019-09-23 13:47:45 +02:00
Javi Martín
7be72df5bf Remove redundant I18n resets in after blocks
We already configure `I18n.locale` and we reset Globalize's fallbacks
before every test.

On the other hand, RSpec automatically resets anything which is stub
with `allow`, so there's no need to use `and_call_original` in an
`after` block.
2019-09-23 13:47:45 +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
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
Senén Rodero Rodríguez
1c76493fa1 Prevent flaky specs because of globalize fallbacks initialization
When any helper, lib, mailer, model or view spec is executed
after a feature, controller or request spec Globalize.fallbacks
returns nil and this can cause some flaky specs. With this
patch we are ensuring to initialize Globalize fallbacks
between specs.

Controller, feature and request specs do not need this patch
because of application_controller is currently initializing
Globalize.fallback on each request.
2019-06-07 19:55:01 +02:00
decabeza
14d85406c3 Fix merge conflicts 2019-04-23 23:38:08 +02:00
Juanjo Bazán
f1e4fb946d updates Devise spec helpers required 2019-04-16 17:28:07 +02:00
Julian Herrero
31ac8b7f55 Change single quotes to double quotes 2019-02-15 11:40:39 +01:00
Javi Martín
dc65c0cdb1 Fix space differences with Madrid's fork 2018-11-30 14:06:33 +01:00
Javi Martín
b153f5f902 Remove redundant Capybara actions
Resetting sessions and driver is automatically done by requiring
'capybara/rspec', as shown by the (lack of) that configuration for RSpec
in the Capybara README, manual testing of those settings, and Capybara's
code itself.
2018-11-30 13:37:16 +01:00
Javi Martín
2f860236a5 Reset page driver after every spec using it
There were some issues because some specs  directly used the driver but
didn't reset it after the test.
2018-11-30 13:34:01 +01:00
Javi Martín
ab870c756a Use Date.current to find published milestones
Using `Date.today` caused some milestones to be published before/after
the date defined by `Rails.application.config.time_zone`.

See also commit AyuntamientoMadird/consul@088c76d for a more detailed
explanation.
2018-11-06 13:02:35 +01:00
Javi Martín
02b8bc6f69 Simplify the way to freeze time in specs 2018-09-19 14:10:18 +02:00
Raimond Garcia
3e4d095e6f Merge pull request #2719 from javierv/2718-fix_flaky_milestone_spec
Fix flaky spec: Budget Investments Show milestones
2018-07-12 16:07:48 +02:00
Javier Martín
de0afe1621 Don't monkey patch ActiveSupport.
It could have side effects (for example, a conflict after upgrading to
Rails 5).

Thanks @aitbw for the suggestion!
2018-07-09 00:06:55 +02:00
Javier Martín
f2ef27d3ae Always set Globalize.locale after I18n.locale.
The test "Budget Investments Show milestones" was failing in certain
cases where `Globalize.locale` had been changed in a previous test.

Since having different values in `Globalize.locale` and `I18n.locale`
has proven to be an issue on the test enviroment, this commit also
changes application code in order to avoid similar situations on
production.

See issue #2718.
2018-07-03 00:52:20 +02:00
Raúl Fuentes
83ca0656b4 Add test for all functinality
new setting set to nil on test to prevent prevent unforeseen
consequences on testing environment
2018-05-22 15:41:10 +02:00
Angel Perez
0a6ee897a7 Configure Capybara sessions to reset after each example 2018-03-27 14:47:51 -04:00
rgarcia
3a182629ca Remove default profiling
This makes tests run a tiny bit faster and cleans up the logs when
running specs locally

We can still configure rspec to run the profiler when we go into improving spec performance
2018-02-06 12:22:34 +01:00
Angel Perez
9a0eca73d7 Fix: Deprecation warnings when running test suite (#2287) 2018-01-09 17:54:46 -04:00
Bertocq
581a6eb3ef Upgrade from factory_girl_rails to factory_bot_rails
Guide at https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md
2018-01-07 23:32:37 +01:00
Bertocq
1441de5107 Enable RSpec/HookArgument cop and fix issues
To be consistent about before/after arguments, as `:each` or `:example`
 are same and default scopes, best not to send an argument in those
 scenarios.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HookArgument
2018-01-07 02:07:19 +01:00
rgarcia
b1c785408c brings back knapsackpro binding 2017-12-05 20:10:40 +01:00
rgarcia
834bbf4be3 removes unnecessary binding 2017-12-05 20:10:40 +01:00
rgarcia
e2d4fbd9ce knapsack_pro setup 2017-12-05 20:10:40 +01:00
BertoCQ
8d7a467397 Merge pull request #1746 from consul/rubocop/rails_fixes
Rubocop fixes 🤖: Rails edition 💎🛤
2017-07-11 22:28:55 +02:00
Bertocq
5a358bce17 Fix all Rails/FilePath rubocop issues 2017-07-10 23:08:02 +02:00
Senén Rodero Rodríguez
1f22286e29 Create rspec shared examples to test followable features on any followable entity. 2017-07-07 13:34:54 +02:00
Bertocq
29b58298db Fix Style/NegatedIf rubocop issue 2017-07-05 11:55:52 +02:00
Alberto Miedes Garcés
861a723724 Only show public_voter if votable.total_votes are above threshold 2017-01-07 17:22:18 +01:00
rgarcia
0939479263 removes custom knapsack configuration 2016-11-20 11:58:31 +01:00
rgarcia
a0a4f3c38e removes time offset warning for parallel builds 2016-11-20 11:56:50 +01:00
rgarcia
f3512a4a6f tries to speed up build with knapsack 2016-11-19 20:13:51 +01:00
rgarcia
bb3c4c6399 adds consistency to ruby code style
Keep a blank line before and after private
Keep a blank line before and after protected
Remove extra empty line at class body end
Remove extra blank line
Add final newline
Use 2 (not 3) spaces for indentation
Use 2 (not 4) spaces for indentation
Remove space before comma
Add space after comma
Remove trailing whitespaces
Remove unnecessary spacing
Use snake_case for variable names
Do not use then for multi-line if
Remove unused block argument - i
Use the new Ruby 1.9 hash syntax
Remove unused assignment to variable
Indent when as deep as case
Align attributes
Align end with def
2016-11-15 11:18:43 +01:00
kikito
289182b145 Adds invisible_captcha to proposals, debates & sps 2016-04-27 16:12:32 +02:00
kikito
eda47effc4 Configures tests to minimize flackyness
Reference: https://bibwild.wordpress.com/2016/02/18/struggling-towards-reliable-capybara-javascript-testing/

The only thing I did not do was removing the random order in the tests.
2016-02-24 11:37:07 +01:00
Josep Jaume Rey Peroy
c83b1804e2 Use en as default locale on tests 2015-11-27 18:04:46 +01:00