From 489e012e1bbf66a576c2cda133836362ef1489ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 25 Mar 2021 16:14:33 +0100 Subject: [PATCH] Test 500 Internal server error page in system spec We were testing what happens when users disable features in the admin panel, so it makes sense to test what happens from the user's point of view when trying to access a disabled feature: they see a page with the test "Internal server error". Whether we should responde with 500 Internal server error page or a 404 Not Found is up to debate; personally I find the latter more appropriate. Code based on the article "Changing Rails consider_all_requests_local in RSpec fails" [1]. [1] http://atodorov.org/blog/2016/04/27/changing-rails-consider_all_requests_local-in-rspec-fails/ --- spec/spec_helper.rb | 12 ++++++++++++ spec/system/admin/feature_flags_spec.rb | 12 +++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1304689c5..f61729b5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -78,6 +78,18 @@ RSpec.configure do |config| sign_in(create(:administrator).user) end + config.before(:each, :show_exceptions) do + config = Rails.application.env_config + + allow(Rails.application).to receive(:env_config) do + config.merge( + "action_dispatch.show_exceptions" => true, + "action_dispatch.show_detailed_exceptions" => false, + "consider_all_requests_local" => false + ) + end + end + config.before(:each, :delay_jobs) do Delayed::Worker.delay_jobs = true end diff --git a/spec/system/admin/feature_flags_spec.rb b/spec/system/admin/feature_flags_spec.rb index 28636ed2d..68ae8502c 100644 --- a/spec/system/admin/feature_flags_spec.rb +++ b/spec/system/admin/feature_flags_spec.rb @@ -14,7 +14,7 @@ describe "Admin feature flags", :admin do end end - scenario "Disable a participatory process" do + scenario "Disable a participatory process", :show_exceptions do setting = Setting.find_by(key: "process.budgets") budget = create(:budget) @@ -33,8 +33,14 @@ describe "Admin feature flags", :admin do expect(page).not_to have_link "Participatory budgets" end - expect { visit budget_path(budget) }.to raise_exception(FeatureFlags::FeatureDisabled) - expect { visit admin_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled) + visit budget_path(budget) + + expect(page).to have_content "Internal server error" + + visit admin_budgets_path + + expect(page).to have_current_path admin_budgets_path + expect(page).to have_content "Internal server error" end scenario "Enable a disabled participatory process" do