Files
nairobi/spec/spec_helper.rb
Javi Martín 37e7eeb6e1 Don't redirect when toggling visible to valuators
After upgrading to Turbolinks 5, redirects are followed on AJAX
requests, so we were accidentally redirecting the user after they mark
an investment as visible to valuators.

There was already a system spec failing due to this issue ("Admin budget
investments Mark as visible to valuators Keeps the valuation tags");
however, it only failed in some cases, so we're adding additional tests.

Ideally we would write a system test to check what happens when users
click on the checkbox. However, from the user's point of view, nothing
happens when they do so, and so testing it is hard. There's a usability
issue here (no feedback is provided to the user indicating the
investment is actually updated when they click on the checkbox and so
they might look for a button to send the form), which also results in a
feature which is difficult to test.

So we're writing two tests instead: one checking the controller does not
redirect when using a JSON request, and one checking the form submits a
JSON request.

I've chosen JSON over AJAX because usually requests to the update action
come from the edit form, and we might change the edit form to send an
AJAX request (and, in this case, Turbolinks would handle the redirect as
mentioned above).

Another option would be to send an AJAX request to a different action,
like it's done for the toggle selection action. I don't have a strong
preference for either option, so I'm leaving it the way it was. At some
point we should change the user interface, though; right now in the same
row there are two actions doing basically the same thing (toggling
valuator visibility and toggling selection) but with very different user
interfaces (one is a checkbox and the other one a link changing its
style depending on the state), resulting in a confusing interface.
2020-10-26 15:12:39 +01:00

144 lines
4.5 KiB
Ruby

require "factory_bot_rails"
require "email_spec"
require "devise"
require "knapsack_pro"
Dir["./spec/models/concerns/*.rb"].each { |f| require f }
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.include RequestSpecHelper, type: :request
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include FactoryBot::Syntax::Methods
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.include(CommonActions)
config.include(ActiveSupport::Testing::TimeHelpers)
config.before(:suite) do
Rails.application.load_seed
end
config.before do |example|
I18n.locale = :en
Globalize.set_fallbacks_to_all_available_locales
Setting["feature.user.skip_verification"] = nil
end
config.around(:each, :race_condition) do |example|
self.use_transactional_tests = false
example.run
self.use_transactional_tests = true
DatabaseCleaner.clean_with(:truncation)
Rails.application.load_seed
end
config.before(:each, type: :system) do
Capybara::Webmock.start
end
config.after(:suite) do
Capybara::Webmock.stop
end
config.after(:each, :page_driver) do
page.driver.reset!
end
config.before(:each, type: :system) do |example|
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
driven_by :headless_chrome
end
config.before(:each, type: :system) do
Bullet.start_request
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(0)
end
config.after(:each, type: :system) do
Bullet.perform_out_of_channel_notifications if Bullet.notification?
Bullet.end_request
end
config.before(:each, :delay_jobs) do
Delayed::Worker.delay_jobs = true
end
config.after(:each, :delay_jobs) do
Delayed::Worker.delay_jobs = false
end
config.before(:each, :remote_translations) do
allow(RemoteTranslations::Microsoft::AvailableLocales)
.to receive(:available_locales).and_return(I18n.available_locales.map(&:to_s))
end
config.around(:each, :with_frozen_time) do |example|
freeze_time { example.run }
end
config.before(:each, :application_zone_west_of_system_zone) do
application_zone = ActiveSupport::TimeZone.new("Quito")
system_zone = ActiveSupport::TimeZone.new("Madrid")
allow(Time).to receive(:zone).and_return(application_zone)
system_time_at_application_end_of_day = Date.current.end_of_day.in_time_zone(system_zone)
allow(Time).to receive(:now).and_return(system_time_at_application_end_of_day)
allow(Date).to receive(:today).and_return(system_time_at_application_end_of_day.to_date)
end
config.before(:each, :with_non_utc_time_zone) do
application_zone = ActiveSupport::TimeZone.new("Madrid")
allow(Time).to receive(:zone).and_return(application_zone)
end
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options.
config.example_status_persistence_file_path = "spec/examples.txt"
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
# config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
config.expect_with(:rspec) { |c| c.syntax = :expect }
end
# Parallel build helper configuration for travis
KnapsackPro::Adapters::RSpecAdapter.bind