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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user