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/
This commit is contained in:
Javi Martín
2021-03-25 16:14:33 +01:00
parent 5ef6c9c2b5
commit 489e012e1b
2 changed files with 21 additions and 3 deletions

View File

@@ -78,6 +78,18 @@ RSpec.configure do |config|
sign_in(create(:administrator).user) sign_in(create(:administrator).user)
end 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 config.before(:each, :delay_jobs) do
Delayed::Worker.delay_jobs = true Delayed::Worker.delay_jobs = true
end end

View File

@@ -14,7 +14,7 @@ describe "Admin feature flags", :admin do
end end
end end
scenario "Disable a participatory process" do scenario "Disable a participatory process", :show_exceptions do
setting = Setting.find_by(key: "process.budgets") setting = Setting.find_by(key: "process.budgets")
budget = create(:budget) budget = create(:budget)
@@ -33,8 +33,14 @@ describe "Admin feature flags", :admin do
expect(page).not_to have_link "Participatory budgets" expect(page).not_to have_link "Participatory budgets"
end end
expect { visit budget_path(budget) }.to raise_exception(FeatureFlags::FeatureDisabled) visit budget_path(budget)
expect { visit admin_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled)
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 end
scenario "Enable a disabled participatory process" do scenario "Enable a disabled participatory process" do