Files
grecia/spec/system/multitenancy_management_mode_spec.rb
taitus 93b35fcecc Redirect root path requests to the tenants administration
When the `multitenancy_management_mode` is enabled.

In order to avoid infinite redirects when regular users try to access
the admin section, we're redirecting to the account page in this case.
Otherwise, the admin section would redirect to the root path, which
would redirect to the admin section, which would redirect to the root
path, and so on.
2024-11-06 11:17:58 +01:00

59 lines
1.7 KiB
Ruby

require "rails_helper"
describe "Multitenancy management mode", :admin do
before do
allow(Rails.application.config).to receive(:multitenancy_management_mode).and_return(true)
Setting["org_name"] = "CONSUL"
end
scenario "renders expected content for multitenancy manage mode in admin section" do
visit admin_root_path
within ".top-links" do
expect(page).not_to have_content "Go back to CONSUL"
end
within ".top-bar" do
expect(page).to have_css "li", count: 2
expect(page).to have_content "My account"
expect(page).to have_content "Sign out"
end
within "#admin_menu" do
expect(page).to have_content "Multitenancy"
expect(page).to have_content "Administrators"
expect(page).to have_css "li", count: 2
end
end
scenario "redirects root path requests to the admin tenants path" do
visit root_path
expect(page).to have_content "CONSUL ADMINISTRATION", normalize_ws: true
expect(page).to have_content "Multitenancy"
expect(page).not_to have_content "Most active proposals"
end
scenario "does not redirect other tenants when visiting the root path", :seed_tenants do
create(:tenant, schema: "mars")
with_subdomain("mars") do
visit root_path
expect(page).to have_content "Most active proposals"
expect(page).not_to have_content "Multitenancy"
expect(page).not_to have_content "CONSUL ADMINISTRATION", normalize_ws: true
end
end
scenario "redirects to account path when regular users try to access the admin section" do
logout
login_as(create(:user))
visit admin_root_path
expect(page).to have_current_path account_path
expect(page).to have_content "You do not have permission to access this page."
end
end